From bee50036d3104de631ec3f0eed3ca761ee4bce5e Mon Sep 17 00:00:00 2001 From: Alina Sbirlea Date: Fri, 22 Jun 2018 17:14:35 +0000 Subject: [LoopUnswitch]Fix comparison for DomTree updates. Summary: In LoopUnswitch when replacing a branch Parent -> Succ with a conditional branch Parent -> True & Parent->False, the DomTree updates should insert an edge for each of True/False if True/False are different than Succ, and delete Parent->Succ edge if both are different. The comparison with Succ appears to be incorect, it's comparing with Parent instead. There is no test failing either before or after this change, but it seems to me this is the right way to do the update. Reviewers: chandlerc, kuhar Subscribers: sanjoy, jlebar, llvm-commits Differential Revision: https://reviews.llvm.org/D48457 llvm-svn: 335369 --- llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms/Scalar/LoopUnswitch.cpp') diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index bc97cacf2b8..b1258675892 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -910,6 +910,7 @@ void LoopUnswitch::EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val, BranchInst *OldBranch, TerminatorInst *TI) { assert(OldBranch->isUnconditional() && "Preheader is not split correctly"); + assert(TrueDest != FalseDest && "Branch targets should be different"); // Insert a conditional branch on LIC to the two preheaders. The original // code is the true version and the new code is the false version. Value *BranchVal = LIC; @@ -942,9 +943,9 @@ void LoopUnswitch::EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val, if (DT) { // First, add both successors. SmallVector Updates; - if (TrueDest != OldBranchParent) + if (TrueDest != OldBranchSucc) Updates.push_back({DominatorTree::Insert, OldBranchParent, TrueDest}); - if (FalseDest != OldBranchParent) + if (FalseDest != OldBranchSucc) Updates.push_back({DominatorTree::Insert, OldBranchParent, FalseDest}); // If both of the new successors are different from the old one, inform the // DT that the edge was deleted. -- cgit v1.2.3