[PATCH] D54706: [LoopSimplifyCFG] Remove phis whilst removing CFG edges

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 19 09:09:02 PST 2018


dmgreen created this revision.
dmgreen added reviewers: mkazantsev, anna.

https://reviews.llvm.org/D54021 adds some extra folding of constant terminators to LoopSimplifyCFG. This fixes up
the phi nodes of successor blocks to those constant folded.


https://reviews.llvm.org/D54706

Files:
  lib/Transforms/Scalar/LoopSimplifyCFG.cpp
  test/Transforms/LoopSimplifyCFG/fold-terminator-phis.ll


Index: test/Transforms/LoopSimplifyCFG/fold-terminator-phis.ll
===================================================================
--- /dev/null
+++ test/Transforms/LoopSimplifyCFG/fold-terminator-phis.ll
@@ -0,0 +1,27 @@
+; RUN: opt -loop-simplifycfg -S < %s | FileCheck %s
+
+; CHECK-LABEL: repo
+; CHECK: %inc = add i32 %i, 2
+define void @repo(i32 %size) {
+entry:
+  br label %loop
+
+loop:
+  %i = phi i32 [ 0, %entry ], [ %inc, %loop2 ]
+  br i1 true, label %loop1, label %loop2
+
+loop1:
+  call void @something()
+  br label %loop2
+
+loop2:
+  %phi = phi i32 [ 1, %loop ], [ 2, %loop1 ]
+  %inc = add i32 %i, %phi
+  %cmp = icmp ult i32 %inc, 3900
+  br i1 %cmp, label %loop, label %end
+
+end:
+  ret void
+}
+
+declare void @something()
Index: lib/Transforms/Scalar/LoopSimplifyCFG.cpp
===================================================================
--- lib/Transforms/Scalar/LoopSimplifyCFG.cpp
+++ lib/Transforms/Scalar/LoopSimplifyCFG.cpp
@@ -242,8 +242,11 @@
       SmallPtrSet<BasicBlock *, 2> DeadSuccessors;
       // Remove all BB's successors except for the live one.
       for (auto *Succ : successors(BB))
-        if (Succ != TheOnlySucc)
+        if (Succ != TheOnlySucc) {
           DeadSuccessors.insert(Succ);
+          for (PHINode &Phi : Succ->phis())
+            Phi.removeIncomingValue(BB);
+        }
 
       IRBuilder<> Builder(BB->getContext());
       Instruction *Term = BB->getTerminator();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54706.174625.patch
Type: text/x-patch
Size: 1438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181119/6405fede/attachment.bin>


More information about the llvm-commits mailing list