llvm.org GIT mirror llvm / 0d3f476
[NewPM] Add Option handling for SimpleLoopUnswitch This patch enables passing options to SimpleLoopUnswitch via the passes pipeline. Reviewers: chandlerc, fedor.sergeev, leonardchan, philip.pfaffe Reviewed By: fedor.sergeev Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D60676 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358880 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 4 months ago
12 changed file(s) with 96 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
14971497 return Opts;
14981498 }
14991499
1500 Expected parseLoopUnswitchOptions(StringRef Params) {
1501 bool Result = false;
1502 while (!Params.empty()) {
1503 StringRef ParamName;
1504 std::tie(ParamName, Params) = Params.split(';');
1505
1506 bool Enable = !ParamName.consume_front("no-");
1507 if (ParamName == "nontrivial") {
1508 Result = Enable;
1509 } else {
1510 return make_error(
1511 formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
1512 .str(),
1513 inconvertibleErrorCode());
1514 }
1515 }
1516 return Result;
1517 }
15001518 } // namespace
15011519
15021520 /// Tests whether a pass name starts with a valid prefix for a default pipeline
16171635
16181636 #define LOOP_PASS(NAME, CREATE_PASS) \
16191637 if (Name == NAME) \
1638 return true;
1639 #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
1640 if (checkParametrizedPassName(Name, NAME)) \
16201641 return true;
16211642 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
16221643 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
20052026 LPM.addPass(CREATE_PASS); \
20062027 return Error::success(); \
20072028 }
2029 #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
2030 if (checkParametrizedPassName(Name, NAME)) { \
2031 auto Params = parsePassParameters(PARSER, Name, NAME); \
2032 if (!Params) \
2033 return Params.takeError(); \
2034 LPM.addPass(CREATE_PASS(Params.get())); \
2035 return Error::success(); \
2036 }
20082037 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
20092038 if (Name == "require<" NAME ">") { \
20102039 LPM.addPass(RequireAnalysisPass< \
289289 LOOP_PASS("irce", IRCEPass())
290290 LOOP_PASS("unroll-and-jam", LoopUnrollAndJamPass())
291291 LOOP_PASS("unroll-full", LoopFullUnrollPass())
292 LOOP_PASS("unswitch", SimpleLoopUnswitchPass())
293292 LOOP_PASS("print-access-info", LoopAccessInfoPrinterPass(dbgs()))
294293 LOOP_PASS("print", IVUsersPrinterPass(dbgs()))
295294 LOOP_PASS("loop-predication", LoopPredicationPass())
296295 LOOP_PASS("guard-widening", GuardWideningPass())
297296 #undef LOOP_PASS
297
298 #ifndef LOOP_PASS_WITH_PARAMS
299 #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
300 #endif
301 LOOP_PASS_WITH_PARAMS("unswitch",
302 [](bool NonTrivial) {
303 return SimpleLoopUnswitchPass(NonTrivial);
304 },
305 parseLoopUnswitchOptions)
306 #undef LOOP_PASS_WITH_PARAMS
0 ; RUN: opt < %s -simple-loop-unswitch -enable-nontrivial-unswitch -S 2>&1 | FileCheck %s
1 ; RUN: opt < %s -passes=unswitch -enable-nontrivial-unswitch -S 2>&1 | FileCheck %s
1 ; RUN: opt < %s -passes='unswitch' -S 2>&1 | FileCheck %s
22 ;
33 ; Checking that (dead) blocks from inner loop are deleted after unswitch.
44 ;
11 ; There should be just a single copy of each loop when strictest mutiplier
22 ; candidates formula (unscaled candidates == 0) is enforced:
33
4 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
4 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
55 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \
6 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
6 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
77 ;
8 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
8 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
99 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \
10 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
10 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1111 ;
1212 ;
1313 ; When we relax the candidates part of a multiplier formula
1414 ; (unscaled candidates == 4) we start getting some unswitches,
1515 ; which leads to siblings multiplier kicking in.
1616 ;
17 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
17 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1818 ; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=1 \
19 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
19 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
2020 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1
2121 ;
2222 ; NB: sort -b is essential here and below, otherwise blanks might lead to different
2323 ; order depending on locale.
2424 ;
25 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
25 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
2626 ; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=2 \
27 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
27 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
2828 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2
2929 ;
3030 ;
3232 ; 2^(num conds) == 2^5 = 32
3333 ; loop nests when cost multiplier is disabled:
3434 ;
35 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=false \
36 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
35 ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
36 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
3737 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32
3838 ;
3939 ; Single loop nest, not unswitched
66 ; There should be just a single copy of each loop when strictest mutiplier
77 ; candidates formula (unscaled candidates == 0) is enforced:
88
9 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
9 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1010 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \
11 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
11 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1212 ;
13 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
13 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1414 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \
15 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
15 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1616 ;
1717 ;
1818 ; When we relax the candidates part of a multiplier formula
1919 ; (unscaled candidates == 2) we start getting some unswitches in outer loops,
2020 ; which leads to siblings multiplier kicking in.
2121 ;
22 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
22 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
2323 ; RUN: -unswitch-num-initial-unscaled-candidates=3 -unswitch-siblings-toplevel-div=1 \
24 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
24 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
2525 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE3-DIV1
2626 ;
2727 ; NB: sort -b is essential here and below, otherwise blanks might lead to different
2828 ; order depending on locale.
2929 ;
30 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
30 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
3131 ; RUN: -unswitch-num-initial-unscaled-candidates=3 -unswitch-siblings-toplevel-div=2 \
32 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
32 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
3333 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE3-DIV2
3434 ;
3535 ; With disabled cost-multiplier we get maximal possible amount of unswitches.
3636 ;
37 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=false \
38 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
37 ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
38 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
3939 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-MAX
4040 ;
4141 ; Single loop nest, not unswitched
11 ; There should be just a single copy of loop when strictest mutiplier candidates
22 ; formula (unscaled candidates == 0) is enforced:
33 ;
4 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
4 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
55 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \
6 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
6 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
77 ;
8 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
8 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
99 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=8 \
10 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
10 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1111 ;
1212 ; With relaxed candidates multiplier (unscaled candidates == 8) we should allow
1313 ; some unswitches to happen until siblings multiplier starts kicking in:
1414 ;
15 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
15 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1616 ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=1 \
17 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP5
17 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP5
1818 ;
1919 ; With relaxed candidates multiplier (unscaled candidates == 8) and with relaxed
2020 ; siblings multiplier for top-level loops (toplevel-div == 8) we should get
2121 ; 2^(num conds) == 2^5 == 32
2222 ; copies of the loop:
2323 ;
24 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
24 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
2525 ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=8 \
26 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32
26 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32
2727 ;
2828 ; Similarly get
2929 ; 2^(num conds) == 2^5 == 32
3030 ; copies of the loop when cost multiplier is disabled:
3131 ;
32 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=false \
33 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32
32 ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
33 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP32
3434 ;
3535 ;
3636 ; Single loop, not unswitched
33 ;
44 ; There we should have just a single loop.
55 ;
6 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
6 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
77 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \
8 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
8 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
99 ;
10 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
10 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1111 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=8 \
12 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
12 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1313 ;
14 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
14 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1515 ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=1 \
16 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
16 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1717 ;
18 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
18 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1919 ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=8 \
20 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
20 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
2121 ;
22 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=false \
23 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
22 ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
23 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
2424 ;
2525 ;
2626 ; Single loop, not unswitched
88 ; When we use the stricted multiplier candidates formula (unscaled candidates == 0)
99 ; we should be getting just a single loop.
1010 ;
11 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
11 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1212 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \
13 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
13 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1414 ;
15 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
15 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
1616 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \
17 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
17 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
1818 ;
1919 ;
2020 ; With relaxed candidates multiplier (unscaled candidates == 8) we should allow
2121 ; some unswitches to happen until siblings multiplier starts kicking in:
2222 ;
23 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
23 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
2424 ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=1 \
25 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
25 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
2626 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-RELAX
2727 ;
2828 ; With relaxed candidates multiplier (unscaled candidates == 8) and with relaxed
2929 ; siblings multiplier for top-level loops (toplevel-div == 8) we should get
3030 ; considerably more copies of the loop (especially top-level ones).
3131 ;
32 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=true \
32 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
3333 ; RUN: -unswitch-num-initial-unscaled-candidates=8 -unswitch-siblings-toplevel-div=8 \
34 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
34 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
3535 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-RELAX2
3636 ;
3737 ; We get hundreds of copies of the loop when cost multiplier is disabled:
3838 ;
39 ; RUN: opt < %s -enable-nontrivial-unswitch -enable-unswitch-cost-multiplier=false \
40 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
39 ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
40 ; RUN: -passes='loop(unswitch),print' -disable-output 2>&1 | \
4141 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-MAX
4242 ;
4343
None ; RUN: opt -passes='loop(unswitch),verify' -enable-nontrivial-unswitch -simple-loop-unswitch-guards -S < %s | FileCheck %s
0 ; RUN: opt -passes='loop(unswitch),verify' -simple-loop-unswitch-guards -S < %s | FileCheck %s
11 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -simple-loop-unswitch-guards -S < %s | FileCheck %s
2 ; RUN: opt -passes='loop(unswitch),verify' -enable-nontrivial-unswitch -simple-loop-unswitch-guards -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s | FileCheck %s
2 ; RUN: opt -passes='loop(unswitch),verify' -simple-loop-unswitch-guards -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s | FileCheck %s
33
44 declare void @llvm.experimental.guard(i1, ...)
55
0 ; Specifically exercise the cost modeling for non-trivial loop unswitching.
11 ;
2 ; RUN: opt -passes='loop(unswitch),verify' -enable-nontrivial-unswitch -unswitch-threshold=5 -S < %s | FileCheck %s
2 ; RUN: opt -passes='loop(unswitch),verify' -unswitch-threshold=5 -S < %s | FileCheck %s
33 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -unswitch-threshold=5 -S < %s | FileCheck %s
44 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -unswitch-threshold=5 -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s | FileCheck %s
55
None ; RUN: opt -passes='loop(unswitch),verify' -enable-nontrivial-unswitch -S < %s | FileCheck %s
0 ; RUN: opt -passes='loop(unswitch),verify' -S < %s | FileCheck %s
11 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -S < %s | FileCheck %s
22 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s | FileCheck %s
33
None ; RUN: opt -passes='print,loop(unswitch,loop-instsimplify),print' -enable-nontrivial-unswitch -S < %s 2>%t.scev | FileCheck %s
1 ; RUN: opt -enable-mssa-loop-dependency=true -verify-memoryssa -passes='print,loop(unswitch,loop-instsimplify),print' -enable-nontrivial-unswitch -S < %s 2>%t.scev | FileCheck %s
0 ; RUN: opt -passes='print,loop(unswitch,loop-instsimplify),print' -S < %s 2>%t.scev | FileCheck %s
1 ; RUN: opt -enable-mssa-loop-dependency=true -verify-memoryssa -passes='print,loop(unswitch,loop-instsimplify),print' -S < %s 2>%t.scev | FileCheck %s
22 ; RUN: FileCheck %s --check-prefix=SCEV < %t.scev
33
44 target triple = "x86_64-unknown-linux-gnu"