Skip to content

Commit 4a0c89a

Browse files
committed
[WebAssembly] Fix fixBrTableIndex removing instruction without checking uses
Fixes: https://bugs.llvm.org/show_bug.cgi?id=52352 Differential Revision: https://reviews.llvm.org/D113230
1 parent 1297c21 commit 4a0c89a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ void fixBrTableIndex(MachineInstr &MI, MachineBasicBlock *MBB,
6161
auto ExtMI = MF.getRegInfo().getVRegDef(MI.getOperand(0).getReg());
6262
if (ExtMI->getOpcode() == WebAssembly::I64_EXTEND_U_I32) {
6363
// Unnecessarily extending a 32-bit value to 64, remove it.
64-
assert(MI.getOperand(0).getReg() == ExtMI->getOperand(0).getReg());
64+
auto ExtDefReg = ExtMI->getOperand(0).getReg();
65+
assert(MI.getOperand(0).getReg() == ExtDefReg);
6566
MI.getOperand(0).setReg(ExtMI->getOperand(1).getReg());
66-
ExtMI->eraseFromParent();
67+
if (MF.getRegInfo().use_nodbg_empty(ExtDefReg)) {
68+
// No more users of extend, delete it.
69+
ExtMI->eraseFromParent();
70+
}
6771
} else {
6872
// Incoming 64-bit value that needs to be truncated.
6973
Register Reg32 =

0 commit comments

Comments
 (0)