[SimpleLoopUnswitch] Fix DT updates for trivial branch unswitching.
authorAlina Sbirlea <asbirlea@google.com>
Sat, 28 Jul 2018 00:01:05 +0000 (00:01 +0000)
committerAlina Sbirlea <asbirlea@google.com>
Sat, 28 Jul 2018 00:01:05 +0000 (00:01 +0000)
Summary:
Fixing 2 issues with the DT update in trivial branch switching, though I don't have a case where DT update fails.
1. After splitting ParentBB->UnswitchedBB edge, new edges become: ParentBB->LoopExitBB->UnswitchedBB, so remove ParentBB->LoopExitBB edge.
2. AFAIU, for multiple CFG changes, DT should be updated using batch updates, vs consecutive addEdge and removeEdge calls.

Reviewers: chandlerc, kuhar

Subscribers: sanjoy, jlebar, llvm-commits

Differential Revision: https://reviews.llvm.org/D49925

llvm-svn: 338180

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

index 34510cb407321ddf376af3de6aca8987f93c67bb..5834b619046b5aceae8b5a6471746442371e1bd0 100644 (file)
@@ -459,9 +459,11 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
                                               *ParentBB, *OldPH, FullUnswitch);
 
   // Now we need to update the dominator tree.
-  DT.insertEdge(OldPH, UnswitchedBB);
+  SmallVector<DominatorTree::UpdateType, 2> DTUpdates;
+  DTUpdates.push_back({DT.Insert, OldPH, UnswitchedBB});
   if (FullUnswitch)
-    DT.deleteEdge(ParentBB, UnswitchedBB);
+    DTUpdates.push_back({DT.Delete, ParentBB, LoopExitBB});
+  DT.applyUpdates(DTUpdates);
 
   // The constant we can replace all of our invariants with inside the loop
   // body. If any of the invariants have a value other than this the loop won't