From 9eb2c0113dfe2c1054e524122ca0e17ad552bb01 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 30 Nov 2020 11:25:07 -0500 Subject: [PATCH] [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. --- llvm/lib/IR/Verifier.cpp | 5 ---- llvm/test/Transforms/LoopRotate/phi-empty.ll | 39 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 llvm/test/Transforms/LoopRotate/phi-empty.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index eda923d..bc24d48 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2565,11 +2565,6 @@ void Verifier::visitBasicBlock(BasicBlock &BB) { SmallVector, 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!", diff --git a/llvm/test/Transforms/LoopRotate/phi-empty.ll b/llvm/test/Transforms/LoopRotate/phi-empty.ll new file mode 100644 index 0000000..9337133 --- /dev/null +++ b/llvm/test/Transforms/LoopRotate/phi-empty.ll @@ -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 +} -- 2.7.4