[PATCH] D92247: [IR][LoopRotate] avoid leaving phi with no operands (PR48296)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 29 07:40:50 PST 2020


spatel updated this revision to Diff 308213.
spatel added a comment.

Patch updated:
Pre-committed the suggested cleanups ( 2cebad7 <https://reviews.llvm.org/rG2cebad702cdff8c320c8afa748626e8cc1b3b2f3> , ce134da <https://reviews.llvm.org/rGce134da4b18c27bbeba4e32f5813b1a3b043066e> ), so this patch becomes even simpler.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92247/new/

https://reviews.llvm.org/D92247

Files:
  llvm/include/llvm/IR/BasicBlock.h
  llvm/lib/IR/BasicBlock.cpp
  llvm/test/Transforms/LoopRotate/phi-empty.ll


Index: llvm/test/Transforms/LoopRotate/phi-empty.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopRotate/phi-empty.ll
@@ -0,0 +1,34 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -lcssa -loop-rotate < %s | FileCheck %s
+
+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:    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
+}
Index: llvm/lib/IR/BasicBlock.cpp
===================================================================
--- llvm/lib/IR/BasicBlock.cpp
+++ llvm/lib/IR/BasicBlock.cpp
@@ -330,7 +330,7 @@
 
   unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
   for (PHINode &Phi : make_early_inc_range(phis())) {
-    Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
+    Phi.removeIncomingValue(Pred);
     if (KeepOneInputPHIs)
       continue;
     // If we have a single predecessor, removeIncomingValue erased the PHI
Index: llvm/include/llvm/IR/BasicBlock.h
===================================================================
--- llvm/include/llvm/IR/BasicBlock.h
+++ llvm/include/llvm/IR/BasicBlock.h
@@ -387,9 +387,9 @@
   /// Update PHI nodes in this BasicBlock before removal of predecessor \p Pred.
   /// Note that this function does not actually remove the predecessor.
   ///
-  /// If \p KeepOneInputPHIs is true then don't remove PHIs that are left with
-  /// zero or one incoming values, and don't simplify PHIs with all incoming
-  /// values the same.
+  /// If \p KeepOneInputPHIs is true, then don't remove PHIs that are left with
+  /// one incoming value and don't simplify PHIs with all incoming values the
+  /// same.
   void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs = false);
 
   bool canSplitPredecessors() const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92247.308213.patch
Type: text/x-patch
Size: 2430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201129/463717e2/attachment.bin>


More information about the llvm-commits mailing list