From: Alina Sbirlea Date: Mon, 14 Oct 2019 23:52:39 +0000 (+0000) Subject: [MemorySSA] Update for partial unswitch. X-Git-Tag: llvmorg-11-init~6508 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7a3353061e965f901ba5cfac366263d6d528f35;p=platform%2Fupstream%2Fllvm.git [MemorySSA] Update for partial unswitch. Update MSSA for blocks cloned when doing partial unswitching. Enable additional testing with MSSA. Resolves PR43641. llvm-svn: 374850 --- diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index 4e7abfc..fa9dbe2 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -2140,6 +2140,13 @@ static void unswitchNontrivialInvariants( // the branch in the split block. buildPartialUnswitchConditionalBranch(*SplitBB, Invariants, Direction, *ClonedPH, *LoopPH); + if (MSSAU) { + // Perform MSSA cloning updates. + for (auto &VMap : VMaps) + MSSAU->updateForClonedLoop(LBRPO, ExitBlocks, *VMap, + /*IgnoreIncomingWithNoClones=*/true); + MSSAU->updateExitBlocksForClonedLoop(ExitBlocks, VMaps, DT); + } DTUpdates.push_back({DominatorTree::Insert, SplitBB, ClonedPH}); } diff --git a/llvm/test/Analysis/MemorySSA/pr43641.ll b/llvm/test/Analysis/MemorySSA/pr43641.ll new file mode 100644 index 0000000..06a6b52 --- /dev/null +++ b/llvm/test/Analysis/MemorySSA/pr43641.ll @@ -0,0 +1,22 @@ +; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -enable-mssa-loop-dependency -verify-memoryssa -S < %s | FileCheck %s +; REQUIRES: asserts + +; CHECK-LABEL: @c +define dso_local void @c(i32 signext %d) local_unnamed_addr { +entry: + br i1 undef, label %while.end, label %while.body.lr.ph + +while.body.lr.ph: ; preds = %entry + %tobool1 = icmp ne i32 %d, 0 + br label %while.body + +while.body: ; preds = %while.body, %while.body.lr.ph + %call = tail call signext i32 bitcast (i32 (...)* @e to i32 ()*)() + %0 = and i1 %tobool1, undef + br i1 %0, label %while.body, label %while.end + +while.end: ; preds = %while.body, %entry + ret void +} + +declare signext i32 @e(...) local_unnamed_addr diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/delete-dead-blocks.ll b/llvm/test/Transforms/SimpleLoopUnswitch/delete-dead-blocks.ll index fa737ed..5659250 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/delete-dead-blocks.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/delete-dead-blocks.ll @@ -1,5 +1,6 @@ ; RUN: opt < %s -simple-loop-unswitch -enable-nontrivial-unswitch -S 2>&1 | FileCheck %s ; RUN: opt < %s -passes='unswitch' -S 2>&1 | FileCheck %s +; RUN: opt < %s -passes='loop-mssa(unswitch)' -S 2>&1 | FileCheck %s ; ; Checking that (dead) blocks from inner loop are deleted after unswitch. ; diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll index 28f7261..d2ca063 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested.ll @@ -10,6 +10,13 @@ ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; ; When we relax the candidates part of a multiplier formula ; (unscaled candidates == 4) we start getting some unswitches, @@ -20,6 +27,11 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1 +; ; NB: sort -b is essential here and below, otherwise blanks might lead to different ; order depending on locale. ; @@ -28,6 +40,10 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=2 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2 ; ; Get ; 2^(num conds) == 2^5 = 32 @@ -37,6 +53,10 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32 +; ; Single loop nest, not unswitched ; LOOP1: Loop at depth 1 containing: ; LOOP1: Loop at depth 2 containing: diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested2.ll b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested2.ll index 7e669f1..e8879e7 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested2.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch-nested2.ll @@ -15,8 +15,16 @@ ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; ; When we relax the candidates part of a multiplier formula +; When we relax the candidates part of a multiplier formula ; (unscaled candidates == 2) we start getting some unswitches in outer loops, ; which leads to siblings multiplier kicking in. ; @@ -25,6 +33,11 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE3-DIV1 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=3 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE3-DIV1 +; ; NB: sort -b is essential here and below, otherwise blanks might lead to different ; order depending on locale. ; @@ -33,12 +46,21 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE3-DIV2 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=3 -unswitch-siblings-toplevel-div=2 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE3-DIV2 +; ; With disabled cost-multiplier we get maximal possible amount of unswitches. ; ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-MAX ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-MAX +; ; Single loop nest, not unswitched ; LOOP1: Loop at depth 1 containing: ; LOOP1-NOT: Loop at depth 1 containing: diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch.ll b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch.ll index 142974c..2644796 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch.ll @@ -10,6 +10,16 @@ ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=8 \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=8 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; With relaxed candidates multiplier (unscaled candidates == 8) we should allow +; some unswitches to happen until siblings multiplier starts kicking in: ; With relaxed candidates multiplier (unscaled candidates == 8) we should allow ; some unswitches to happen until siblings multiplier starts kicking in: ; @@ -17,6 +27,10 @@ ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=1 \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP5 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP5 +; ; With relaxed candidates multiplier (unscaled candidates == 8) and with relaxed ; siblings multiplier for top-level loops (toplevel-div == 8) we should get ; 2^(num conds) == 2^5 == 32 @@ -26,6 +40,10 @@ ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=8 \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=8 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32 +; ; Similarly get ; 2^(num conds) == 2^5 == 32 ; copies of the loop when cost multiplier is disabled: @@ -33,6 +51,8 @@ ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32 ; ; Single loop, not unswitched ; LOOP1: Loop at depth 1 containing: diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch2.ll b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch2.ll index 5cc5945..636039b 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch2.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-nontrivial-unswitch2.ll @@ -24,6 +24,26 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=8 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=8 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; ; Single loop, not unswitched ; LOOP1: Loop at depth 1 containing: ; LOOP1-NOT: Loop at depth 1 containing: diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-switch-unswitch.ll b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-switch-unswitch.ll index 312c741..35d431e 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/exponential-switch-unswitch.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/exponential-switch-unswitch.ll @@ -17,6 +17,13 @@ ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 +; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 ; ; With relaxed candidates multiplier (unscaled candidates == 8) we should allow ; some unswitches to happen until siblings multiplier starts kicking in: @@ -26,6 +33,11 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-RELAX ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=1 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-RELAX +; ; With relaxed candidates multiplier (unscaled candidates == 8) and with relaxed ; siblings multiplier for top-level loops (toplevel-div == 8) we should get ; considerably more copies of the loop (especially top-level ones). @@ -35,12 +47,20 @@ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-RELAX2 ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ +; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=8 \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-RELAX2 +; ; We get hundreds of copies of the loop when cost multiplier is disabled: ; ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \ ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-MAX ; +; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ +; RUN: -passes='loop-mssa(unswitch),print' -disable-output 2>&1 | \ +; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-MAX ; Single loop nest, not unswitched ; LOOP1: Loop at depth 1 containing: diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-cost.ll b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-cost.ll index 8862d01..692799d 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-cost.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-cost.ll @@ -1,6 +1,7 @@ ; Specifically exercise the cost modeling for non-trivial loop unswitching. ; ; RUN: opt -passes='loop(unswitch),verify' -unswitch-threshold=5 -S < %s | FileCheck %s +; RUN: opt -passes='loop-mssa(unswitch),verify' -unswitch-threshold=5 -S < %s | FileCheck %s ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -unswitch-threshold=5 -S < %s | FileCheck %s ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -unswitch-threshold=5 -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s | FileCheck %s diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll index 8f743ca..6dd2cde 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll @@ -1,5 +1,6 @@ ; REQUIRES: asserts ; RUN: opt -passes='unswitch' -disable-output -S < %s +; RUN: opt -passes='loop-mssa(unswitch)' -disable-output -S < %s ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -disable-output -S < %s ; This loop shouldn't trigger asserts in SimpleLoopUnswitch. diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll index 9f2e8a4..0aec52d 100644 --- a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll @@ -1,4 +1,5 @@ ; RUN: opt -passes='loop(unswitch),verify' -S < %s | FileCheck %s +; RUN: opt -passes='loop-mssa(unswitch),verify' -S < %s | FileCheck %s ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -S < %s | FileCheck %s ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s | FileCheck %s