Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
[AMDGPU] Fix crash in phi-elimination hook.
Browse files Browse the repository at this point in the history
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371649 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
hliao2 committed Sep 11, 2019
1 parent 44c12ea commit de8eddb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Target/AMDGPU/SIInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions test/CodeGen/AMDGPU/phi-elimination-assertion.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit de8eddb

Please sign in to comment.