[PATCH] D68032: Handle successor's PHI node correctly when flattening CFG merges two if-regions

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 08:18:18 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL372989: Handle successor's PHI node correctly when flattening CFG merges two if-regions (authored by kuhar, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D68032?vs=221832&id=221960#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68032

Files:
  llvm/trunk/lib/Transforms/Utils/FlattenCFG.cpp
  llvm/trunk/test/Transforms/Util/flattencfg.ll


Index: llvm/trunk/test/Transforms/Util/flattencfg.ll
===================================================================
--- llvm/trunk/test/Transforms/Util/flattencfg.ll
+++ llvm/trunk/test/Transforms/Util/flattencfg.ll
@@ -54,3 +54,33 @@
   br i1 %1, label %bb4, label %bb3
 }
 
+; CHECK-LABEL: @test_not_crash3
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    %a_eq_0 = icmp eq i32 %a, 0
+; CHECK-NEXT:    %a_eq_1 = icmp eq i32 %a, 1
+; CHECK-NEXT:    [[COND:%[a-z0-9]+]] = or i1 %a_eq_0, %a_eq_1
+; CHECK-NEXT:    br i1 [[COND]], label %bb2, label %bb3
+; CHECK:       bb2:
+; CHECK-NEXT:    br label %bb3
+; CHECK:       bb3:
+; CHECK-NEXT:    %check_badref = phi i32 [ 17, %entry ], [ 11, %bb2 ]
+; CHECK-NEXT:    ret void
+define void @test_not_crash3(i32 %a) #0 {
+entry:
+  %a_eq_0 = icmp eq i32 %a, 0
+  br i1 %a_eq_0, label %bb0, label %bb1
+
+bb0:                                              ; preds = %entry
+  br label %bb1
+
+bb1:                                              ; preds = %bb0, %entry
+  %a_eq_1 = icmp eq i32 %a, 1
+  br i1 %a_eq_1, label %bb2, label %bb3
+
+bb2:                                              ; preds = %bb1
+  br label %bb3
+
+bb3:                                              ; preds = %bb2, %bb1
+  %check_badref = phi i32 [ 17, %bb1 ], [ 11, %bb2 ]
+  ret void
+}
Index: llvm/trunk/lib/Transforms/Utils/FlattenCFG.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/FlattenCFG.cpp
+++ llvm/trunk/lib/Transforms/Utils/FlattenCFG.cpp
@@ -67,7 +67,7 @@
 /// Before:
 ///   ......
 ///   %cmp10 = fcmp une float %tmp1, %tmp2
-///   br i1 %cmp1, label %if.then, label %lor.rhs
+///   br i1 %cmp10, label %if.then, label %lor.rhs
 ///
 /// lor.rhs:
 ///   ......
@@ -453,6 +453,16 @@
   PBI->replaceUsesOfWith(CC, NC);
   Builder.SetInsertPoint(SaveInsertBB, SaveInsertPt);
 
+  // Handle PHI node to replace its predecessors to FirstEntryBlock.
+  for (BasicBlock *Succ : successors(PBI)) {
+    for (PHINode &Phi : Succ->phis()) {
+      for (unsigned i = 0, e = Phi.getNumIncomingValues(); i != e; ++i) {
+        if (Phi.getIncomingBlock(i) == SecondEntryBlock)
+          Phi.setIncomingBlock(i, FirstEntryBlock);
+      }
+    }
+  }
+
   // Remove IfTrue1
   if (IfTrue1 != FirstEntryBlock) {
     IfTrue1->dropAllReferences();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68032.221960.patch
Type: text/x-patch
Size: 2328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190926/09eefe89/attachment.bin>


More information about the llvm-commits mailing list