[llvm] 9eb2c01 - [IR][LoopRotate] remove assertion that phi must have at least one operand

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 30 08:32:50 PST 2020


Author: Sanjay Patel
Date: 2020-11-30T11:32:42-05:00
New Revision: 9eb2c0113dfe2c1054e524122ca0e17ad552bb01

URL: https://github.com/llvm/llvm-project/commit/9eb2c0113dfe2c1054e524122ca0e17ad552bb01
DIFF: https://github.com/llvm/llvm-project/commit/9eb2c0113dfe2c1054e524122ca0e17ad552bb01.diff

LOG: [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.

Added: 
    llvm/test/Transforms/LoopRotate/phi-empty.ll

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index eda923da8df8..bc24d488d2f7 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -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!",

diff  --git a/llvm/test/Transforms/LoopRotate/phi-empty.ll b/llvm/test/Transforms/LoopRotate/phi-empty.ll
new file mode 100644
index 000000000000..9337133f8903
--- /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
+}


        


More information about the llvm-commits mailing list