[PATCH] D67451: [AMDGPU] Fix crash in phi-elimination hook.
Michael Liao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 09:15:29 PDT 2019
hliao created this revision.
hliao added reviewers: alex-t, rampitec, arsenm.
Herald added subscribers: llvm-commits, hiraditya, t-tye, tpr, dstuttard, nhaehnle, wdng, jvesely, kzhuravl.
Herald added a project: LLVM.
- Pre-check in case there's just a single PHI insn.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67451
Files:
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/test/CodeGen/AMDGPU/phi-elimination-assertion.mir
Index: llvm/test/CodeGen/AMDGPU/phi-elimination-assertion.mir
===================================================================
--- llvm/test/CodeGen/AMDGPU/phi-elimination-assertion.mir
+++ llvm/test/CodeGen/AMDGPU/phi-elimination-assertion.mir
@@ -62,8 +62,32 @@
S_NOP 0, implicit %4
...
+# The following test crashes in phi-elimination hooks.
+#
# CHECK-LABEL: name: bar
# CHECK: bb.3:
# CHECK-NEXT: dead %3:sreg_32_xm0 = IMPLICIT_DEF
# CHECK-NEXT: %2:sreg_32_xm0 = COPY killed %4
# CHECK-NEXT: S_NOP 0, implicit killed %2
+
+---
+name: bax
+tracksRegLiveness: true
+body: |
+ bb.0:
+ S_CBRANCH_SCC0 %bb.2, implicit undef $scc
+
+ bb.1:
+ %1:sreg_32_xm0 = S_MOV_B32 255
+ S_BRANCH %bb.3
+
+ bb.2:
+ %2:sreg_32_xm0 = S_MOV_B32 254
+
+ bb.3:
+ %3:sreg_32_xm0 = PHI %2, %bb.2, %1, %bb.1
+...
+
+# CHECK-LABEL: name: bax
+# CHECK: bb.3:
+# CHECK-NEXT: %2:sreg_32_xm0 = COPY killed %3
Index: llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -6415,11 +6415,13 @@
MachineBasicBlock &MBB, MachineBasicBlock::iterator LastPHIIt,
const DebugLoc &DL, Register Src, Register Dst) const {
auto Cur = MBB.begin();
- do {
+ while (Cur != MBB.end()) {
if (!Cur->isPHI() && Cur->readsRegister(Dst))
return BuildMI(MBB, Cur, DL, get(TargetOpcode::COPY), Dst).addReg(Src);
++Cur;
- } while (Cur != MBB.end() && Cur != LastPHIIt);
+ if (Cur == LastPHIIt)
+ break;
+ }
return TargetInstrInfo::createPHIDestinationCopy(MBB, LastPHIIt, DL, Src,
Dst);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67451.219732.patch
Type: text/x-patch
Size: 1776 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190911/e30ef610/attachment.bin>
More information about the llvm-commits
mailing list