1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[SimplifyCFG] Teach SinkCommonCodeFromPredecessors() to preserve DomTree

This commit is contained in:
Roman Lebedev 2020-12-29 22:32:45 +03:00
parent 0da61f469b
commit 1f70a467c3
2 changed files with 6 additions and 4 deletions

View File

@ -1812,7 +1812,8 @@ namespace {
/// true, sink any common code from the predecessors to BB.
/// We also allow one predecessor to end with conditional branch (but no more
/// than one).
static bool SinkCommonCodeFromPredecessors(BasicBlock *BB) {
static bool SinkCommonCodeFromPredecessors(BasicBlock *BB,
DomTreeUpdater *DTU) {
// We support two situations:
// (1) all incoming arcs are unconditional
// (2) one incoming arc is conditional
@ -1930,7 +1931,8 @@ static bool SinkCommonCodeFromPredecessors(BasicBlock *BB) {
LLVM_DEBUG(dbgs() << "SINK: Splitting edge\n");
// We have a conditional edge and we're going to sink some instructions.
// Insert a new block postdominating all blocks we're going to sink from.
if (!SplitBlockPredecessors(BB, UnconditionalPreds, ".sink.split"))
if (!SplitBlockPredecessors(BB, UnconditionalPreds, ".sink.split",
DTU ? &DTU->getDomTree() : nullptr))
// Edges couldn't be split.
return false;
Changed = true;
@ -6461,7 +6463,7 @@ bool SimplifyCFGOpt::simplifyOnceImpl(BasicBlock *BB) {
return true;
if (SinkCommon && Options.SinkCommonInsts)
Changed |= SinkCommonCodeFromPredecessors(BB);
Changed |= SinkCommonCodeFromPredecessors(BB, DTU);
IRBuilder<> Builder(BB);

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -simplifycfg -sink-common-insts -S | FileCheck -enable-var-scope %s
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -sink-common-insts -S | FileCheck -enable-var-scope %s
; RUN: opt < %s -passes='simplify-cfg<sink-common-insts>' -S | FileCheck -enable-var-scope %s
define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {