[PATCH] D62713: [MIR-Canon] Hardening propagateLocalCopies.
Puyan Lotfi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 30 18:12:39 PDT 2019
plotfi created this revision.
plotfi added reviewers: compnerd, bogner.
Herald added subscribers: llvm-commits, hiraditya, nhaehnle, jvesely.
Herald added a project: LLVM.
[MIR-Canon] Hardening propagateLocalCopies.
- If there is no register class for a COPY's src or dst, bail.
- Fixes uses iterator clobbering bug.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D62713
Files:
llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
llvm/test/CodeGen/MIR/AMDGPU/mir-canon-multi.mir
Index: llvm/test/CodeGen/MIR/AMDGPU/mir-canon-multi.mir
===================================================================
--- llvm/test/CodeGen/MIR/AMDGPU/mir-canon-multi.mir
+++ llvm/test/CodeGen/MIR/AMDGPU/mir-canon-multi.mir
@@ -1,8 +1,8 @@
# RUN: llc -o - -march=amdgcn -run-pass mir-canonicalizer -x mir %s | FileCheck %s
# CHECK: %namedVReg1352:vgpr_32 = COPY %namedVReg4353
+# CHECK: %namedVReg1358:vgpr_32 = COPY %namedVReg1361
# CHECK: %namedVReg1359:vgpr_32 = COPY %namedVReg1362
-# CHECK: %namedVReg1360:vgpr_32 = COPY %namedVReg1363
...
---
name: foo
Index: llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
===================================================================
--- llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
+++ llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
@@ -330,7 +330,6 @@
}
for (MachineInstr *MI : Copies) {
-
if (!MI->getOperand(0).isReg())
continue;
if (!MI->getOperand(1).isReg())
@@ -343,15 +342,19 @@
continue;
if (!TargetRegisterInfo::isVirtualRegister(Src))
continue;
+ // Not folding COPY instructions if regbankselect has not set the RCs.
+ if (nullptr == MRI.getRegClassOrNull(Dst))
+ continue;
if (MRI.getRegClass(Dst) != MRI.getRegClass(Src))
continue;
- for (auto UI = MRI.use_begin(Dst); UI != MRI.use_end(); ++UI) {
- MachineOperand *MO = &*UI;
+ std::vector<MachineOperand *> Uses;
+ for (auto UI = MRI.use_begin(Dst); UI != MRI.use_end(); ++UI)
+ Uses.push_back(&*UI);
+ for (auto *MO : Uses)
MO->setReg(Src);
- Changed = true;
- }
+ Changed = true;
MI->eraseFromParent();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62713.202347.patch
Type: text/x-patch
Size: 1646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190531/1bb48c72/attachment.bin>
More information about the llvm-commits
mailing list