[PATCH] D113230: [WebAssembly] Fix fixBrTableIndex removing instruction without checking uses
Wouter van Oortmerssen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 4 17:23:05 PDT 2021
aardappel created this revision.
aardappel added reviewers: dschuff, tlively, aheejin.
Herald added subscribers: wingo, ecnelises, arphaman, sunfish, hiraditya, jgravelle-google, sbc100.
aardappel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Fixes: https://bugs.llvm.org/show_bug.cgi?id=52352
https://reviews.llvm.org/D113230
Files:
llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
Index: llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
@@ -61,9 +61,17 @@
auto ExtMI = MF.getRegInfo().getVRegDef(MI.getOperand(0).getReg());
if (ExtMI->getOpcode() == WebAssembly::I64_EXTEND_U_I32) {
// Unnecessarily extending a 32-bit value to 64, remove it.
- assert(MI.getOperand(0).getReg() == ExtMI->getOperand(0).getReg());
+ auto ExtDefReg = ExtMI->getOperand(0).getReg();
+ assert(MI.getOperand(0).getReg() == ExtDefReg);
MI.getOperand(0).setReg(ExtMI->getOperand(1).getReg());
+ // Check if the br_table was the only user of the extend.
+ for (MachineInstr &UseMI : MF.getRegInfo().use_instructions(ExtDefReg)) {
+ if (&UseMI != &MI)
+ goto user_found;
+ }
+ // No more users of extend, delete it.
ExtMI->eraseFromParent();
+ user_found:;
} else {
// Incoming 64-bit value that needs to be truncated.
Register Reg32 =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113230.384918.patch
Type: text/x-patch
Size: 1112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211105/2ed52277/attachment.bin>
More information about the llvm-commits
mailing list