Author: Roman Lebedev Date: 2020-12-30T00:48:10+03:00 New Revision: 18c407bf4c16800a836abe8096a7e4c41ce46b24
URL: https://github.com/llvm/llvm-project/commit/18c407bf4c16800a836abe8096a7e4c41ce46b24 DIFF: https://github.com/llvm/llvm-project/commit/18c407bf4c16800a836abe8096a7e4c41ce46b24.diff LOG: [SimplifyCFG] Teach HoistThenElseCodeToIf() to preserve DomTree Added: Modified: llvm/lib/Transforms/Utils/SimplifyCFG.cpp llvm/test/Transforms/GVNSink/indirect-call.ll llvm/test/Transforms/GVNSink/sink-common-code.ll llvm/test/Transforms/SimplifyCFG/BrUnwind.ll llvm/test/Transforms/SimplifyCFG/HoistCode.ll llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll llvm/test/Transforms/SimplifyCFG/pr39807.ll Removed: ################################################################################ diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 41af29b82791..6af60467cf45 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1508,11 +1508,19 @@ bool SimplifyCFGOpt::HoistThenElseCodeToIf(BranchInst *BI, } } + SmallVector<DominatorTree::UpdateType, 4> Updates; + // Update any PHI nodes in our new successors. - for (BasicBlock *Succ : successors(BB1)) + for (BasicBlock *Succ : successors(BB1)) { AddPredecessorToBlock(Succ, BIParent, BB1); + Updates.push_back({DominatorTree::Insert, BIParent, Succ}); + } + for (BasicBlock *Succ : successors(BI)) + Updates.push_back({DominatorTree::Delete, BIParent, Succ}); EraseTerminatorAndDCECond(BI); + if (DTU) + DTU->applyUpdatesPermissive(Updates); return Changed; } diff --git a/llvm/test/Transforms/GVNSink/indirect-call.ll b/llvm/test/Transforms/GVNSink/indirect-call.ll index 66c1a4f647a9..db84fe7410fd 100644 --- a/llvm/test/Transforms/GVNSink/indirect-call.ll +++ b/llvm/test/Transforms/GVNSink/indirect-call.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -gvn-sink -simplifycfg -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s +; RUN: opt < %s -gvn-sink -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s declare i8 @ext(i1) diff --git a/llvm/test/Transforms/GVNSink/sink-common-code.ll b/llvm/test/Transforms/GVNSink/sink-common-code.ll index 4131fb37485f..d0b533b4ac57 100644 --- a/llvm/test/Transforms/GVNSink/sink-common-code.ll +++ b/llvm/test/Transforms/GVNSink/sink-common-code.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -gvn-sink -simplifycfg -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s +; RUN: opt < %s -gvn-sink -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) { entry: diff --git a/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll b/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll index 6cd3ad6e4b02..c40f5513cebf 100644 --- a/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll +++ b/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | \ +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | \ ; RUN: not grep "br label" define void @test(i1 %C) { diff --git a/llvm/test/Transforms/SimplifyCFG/HoistCode.ll b/llvm/test/Transforms/SimplifyCFG/HoistCode.ll index 975107da4928..51baa5b7f9b3 100644 --- a/llvm/test/Transforms/SimplifyCFG/HoistCode.ll +++ b/llvm/test/Transforms/SimplifyCFG/HoistCode.ll @@ -1,6 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -passes=simplifycfg -hoist-common-insts=true -S | FileCheck %s -; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | FileCheck %s +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | FileCheck %s define void @foo(i1 %C, i32* %P) { ; CHECK-LABEL: @foo( diff --git a/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll b/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll index 78bcd345daf9..122368406118 100644 --- a/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll +++ b/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll @@ -2,7 +2,7 @@ ; a PHI node and a return. Make sure the simplify cfg can straighten out this ; important case. This is basically the most trivial form of tail-duplication. -; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | \ +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | \ ; RUN: not grep "br label" define i32 @test(i1 %B, i32 %A, i32 %B.upgrd.1) { diff --git a/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll b/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll index 10918376a100..c682c1eebf0e 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll +++ b/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | FileCheck %s +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -hoist-common-insts=true | FileCheck %s ; ModuleID = 'cppeh-simplify.cpp' target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" diff --git a/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll b/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll index 1013fab20d1c..69d5378b256d 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll +++ b/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -S -simplifycfg -hoist-common-insts=true | FileCheck %s +; RUN: opt < %s -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true | FileCheck %s ; SimplifyCFG can hoist any common code in the 'then' and 'else' blocks to ; the 'if' basic block. diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll b/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll index 958cd35a172f..2b43b511432e 100644 --- a/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll +++ b/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | not grep br +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -hoist-common-insts=true | not grep br declare void @bar(i32) diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll b/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll index 82d4538bcbeb..82c1fa7ba231 100644 --- a/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll +++ b/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | FileCheck %s +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | FileCheck %s define void @foo(i1 %c, i8* %p) { ; CHECK: if: diff --git a/llvm/test/Transforms/SimplifyCFG/pr39807.ll b/llvm/test/Transforms/SimplifyCFG/pr39807.ll index 1214c6fbeafb..053b20e5ae6e 100644 --- a/llvm/test/Transforms/SimplifyCFG/pr39807.ll +++ b/llvm/test/Transforms/SimplifyCFG/pr39807.ll @@ -1,4 +1,4 @@ -; RUN: opt -S -simplifycfg -hoist-common-insts=true < %s | FileCheck %s +; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true < %s | FileCheck %s declare void @personality() _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits