[llvm] r371649 - [AMDGPU] Fix crash in phi-elimination hook.
Michael Liao via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 12:55:20 PDT 2019
Author: hliao
Date: Wed Sep 11 12:55:20 2019
New Revision: 371649
URL: http://llvm.org/viewvc/llvm-project?rev=371649&view=rev
Log:
[AMDGPU] Fix crash in phi-elimination hook.
Summary: - Pre-check in case there's just a single PHI insn.
Reviewers: alex-t, rampitec, arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, dstuttard, tpr, t-tye, hiraditya, llvm-commits, yaxunl
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67451
Modified:
llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/trunk/test/CodeGen/AMDGPU/phi-elimination-assertion.mir
Modified: llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp?rev=371649&r1=371648&r2=371649&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp Wed Sep 11 12:55:20 2019
@@ -6415,11 +6415,13 @@ MachineInstr *SIInstrInfo::createPHIDest
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);
Modified: llvm/trunk/test/CodeGen/AMDGPU/phi-elimination-assertion.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/phi-elimination-assertion.mir?rev=371649&r1=371648&r2=371649&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/phi-elimination-assertion.mir (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/phi-elimination-assertion.mir Wed Sep 11 12:55:20 2019
@@ -67,3 +67,29 @@ body: |
# 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
+
+
+# The following test crashes in phi-elimination hooks.
+#
+
+---
+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
More information about the llvm-commits
mailing list