OSDN Git Service

[SimplifyCFG] FoldValueComparisonIntoPredecessors(): don't insert a DomTree edge...
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 11 Jan 2021 21:21:25 +0000 (00:21 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 11 Jan 2021 23:09:47 +0000 (02:09 +0300)
When we are adding edges to the terminator and potentially turning it
into a switch (if it wasn't already), it is possible that the
case we're adding will share it's destination with one of the
preexisting cases, in which case there is no domtree edge to add.

Indeed, this change does not have a test coverage change.
This failure has been exposed in an existing test coverage
by a follow-up patch that switches to lazy domtreeupdater mode,
and removes domtree verification from
SimplifyCFGOpt::simplifyOnce()/SimplifyCFGOpt::run(),
IOW it does not appear feasible to add dedicated test coverage here.

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

index 7158133..880d0e7 100644 (file)
@@ -1267,7 +1267,8 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
           (void)I;
           AddPredecessorToBlock(NewSuccessor.first, Pred, BB);
         }
-        Updates.push_back({DominatorTree::Insert, Pred, NewSuccessor.first});
+        if (!is_contained(successors(Pred), NewSuccessor.first))
+          Updates.push_back({DominatorTree::Insert, Pred, NewSuccessor.first});
       }
 
       Builder.SetInsertPoint(PTI);