From b8121b2e62d58ca42aa78b0dd644af9d096957a3 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 29 Dec 2020 22:32:45 +0300 Subject: [PATCH] [SimplifyCFG] Teach SinkCommonCodeFromPredecessors() to preserve DomTree --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 8 +++++--- llvm/test/Transforms/SimplifyCFG/sink-common-code.ll | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 6af6046..2fcfc55 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -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); diff --git a/llvm/test/Transforms/SimplifyCFG/sink-common-code.ll b/llvm/test/Transforms/SimplifyCFG/sink-common-code.ll index 00329ae..48dd2d9 100644 --- a/llvm/test/Transforms/SimplifyCFG/sink-common-code.ll +++ b/llvm/test/Transforms/SimplifyCFG/sink-common-code.ll @@ -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' -S | FileCheck -enable-var-scope %s define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) { -- 2.7.4