[PATCH] D77620: [SimpleLoopUnswitch] Do not delete DT edge when a duplicate exists.

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 19:06:36 PDT 2020


asbirlea created this revision.
asbirlea added reviewers: chandlerc, uabelho.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
asbirlea updated this revision to Diff 255566.
asbirlea added a comment.

Nit in test.


For the unswitched blocks that were split, there may be a duplicate edge
that was kept. Check this when updating the DominatorTree.
Resolves PR45355.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77620

Files:
  llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
  llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch.ll


Index: llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch.ll
===================================================================
--- llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch.ll
@@ -1243,3 +1243,39 @@
 ; CHECK:       loopexit:
 ; CHECK-NEXT:    ret
 }
+
+; PR45355
+define void @test_unswitch_switch_with_duplicate_edge() {
+; CHECK-LABEL: @test_unswitch_switch_with_duplicate_edge()
+entry:
+  br label %lbl1
+
+lbl1.loopexit:                                    ; preds = %for.cond1
+  unreachable
+
+lbl1:                                             ; preds = %entry
+  %cleanup.dest.slot.0 = select i1 undef, i32 5, i32 undef
+  br label %for.cond1
+
+for.cond1:                                        ; preds = %for.cond1, %lbl1
+  switch i32 %cleanup.dest.slot.0, label %UnifiedUnreachableBlock [
+    i32 0, label %for.cond1
+    i32 5, label %UnifiedUnreachableBlock
+    i32 2, label %lbl1.loopexit
+  ]
+
+UnifiedUnreachableBlock:                          ; preds = %for.cond1, %for.cond1
+  unreachable
+
+; CHECK: lbl1:
+; CHECK-NEXT:  %cleanup.dest.slot.0 = select i1 undef, i32 5, i32 undef
+; CHECK-NEXT:  switch i32 %cleanup.dest.slot.0, label %lbl1.split [
+; CHECK-NEXT:    i32 5, label %UnifiedUnreachableBlock.split
+; CHECK-NEXT:    i32 2, label %lbl1.loopexit
+; CHECK-NEXT:  ]
+
+; CHECK: lbl1.split:
+; CHECK-NEXT:  switch i32 %cleanup.dest.slot.0, label %UnifiedUnreachableBlock [
+; CHECK-NEXT:    i32 0, label %lbl1.split.split
+; CHECK-NEXT:  ]
+}
Index: llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -826,7 +826,9 @@
     DTUpdates.push_back({DT.Insert, OldPH, UnswitchedExitBB});
   }
   for (auto SplitUnswitchedPair : SplitExitBBMap) {
-    DTUpdates.push_back({DT.Delete, ParentBB, SplitUnswitchedPair.first});
+    // If the deleted edge was not duplicated in the switch, delete from the DT.
+    if (!llvm::is_contained(successors(ParentBB), SplitUnswitchedPair.first))
+      DTUpdates.push_back({DT.Delete, ParentBB, SplitUnswitchedPair.first});
     DTUpdates.push_back({DT.Insert, OldPH, SplitUnswitchedPair.second});
   }
   DT.applyUpdates(DTUpdates);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77620.255566.patch
Type: text/x-patch
Size: 2360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200407/da1178ad/attachment.bin>


More information about the llvm-commits mailing list