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
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);
# 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