[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

llvm-svn: 371649
This commit is contained in:
Michael Liao 2019-09-11 19:55:20 +00:00
parent 4a5dd4a881
commit 7957d4c015
2 changed files with 30 additions and 2 deletions

View File

@ -6415,11 +6415,13 @@ MachineInstr *SIInstrInfo::createPHIDestinationCopy(
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);

View File

@ -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