[IR][LoopRotate] remove assertion that phi must have at least one operand

This was suggested in D92247 - I initially committed an alternate
fix ( bfd2c216ea ) to avoid the crash/assert shown in
https://llvm.org/PR48296 ,
but that was reverted because it caused msan failures on other
tests. We can try to revive that patch using the test included
here, but I do not have an immediate plan to isolate that problem.
This commit is contained in:
Sanjay Patel
2020-11-30 11:25:07 -05:00
parent 76d1026b59
commit 9eb2c0113d
2 changed files with 39 additions and 5 deletions

View File

@@ -2565,11 +2565,6 @@ void Verifier::visitBasicBlock(BasicBlock &BB) {
SmallVector<std::pair<BasicBlock*, Value*>, 8> Values;
llvm::sort(Preds);
for (const PHINode &PN : BB.phis()) {
// Ensure that PHI nodes have at least one entry!
Assert(PN.getNumIncomingValues() != 0,
"PHI nodes must have at least one entry. If the block is dead, "
"the PHI should be removed!",
&PN);
Assert(PN.getNumIncomingValues() == Preds.size(),
"PHINode should have one entry for each predecessor of its "
"parent basic block!",

View File

@@ -0,0 +1,39 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -lcssa -loop-rotate < %s | FileCheck %s
; After rotate, the phi has no operands because it has no predecessors.
; We might want to delete that instruction instead, but we do not
; fail/assert by assuming that the phi is invalid IR.
define void @PR48296(i1 %cond) {
; CHECK-LABEL: @PR48296(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: br i1 [[COND:%.*]], label [[INC:%.*]], label [[LOOP_BACKEDGE:%.*]]
; CHECK: loop.backedge:
; CHECK-NEXT: br label [[LOOP]]
; CHECK: dead:
; CHECK-NEXT: unreachable
; CHECK: inc:
; CHECK-NEXT: br label [[LOOP_BACKEDGE]]
; CHECK: return:
; CHECK-NEXT: [[R:%.*]] = phi i32
; CHECK-NEXT: ret void
;
entry:
br label %loop
loop:
br i1 %cond, label %inc, label %loop
dead: ; No predecessors!
br i1 %cond, label %inc, label %return
inc:
br label %loop
return:
%r = phi i32 [ undef, %dead ]
ret void
}