2 ; There should be just a single copy of each loop when strictest mutiplier
3 ; candidates formula (unscaled candidates == 0) is enforced:
5 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
6 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \
7 ; RUN: -passes='loop(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
9 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
10 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \
11 ; RUN: -passes='loop(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
13 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
14 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=1 \
15 ; RUN: -passes='loop-mssa(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
17 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
18 ; RUN: -unswitch-num-initial-unscaled-candidates=0 -unswitch-siblings-toplevel-div=16 \
19 ; RUN: -passes='loop-mssa(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1
21 ; When we relax the candidates part of a multiplier formula
22 ; (unscaled candidates == 4) we start getting some unswitches,
23 ; which leads to siblings multiplier kicking in.
25 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
26 ; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=1 \
27 ; RUN: -passes='loop(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
28 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1
30 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
31 ; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=1 \
32 ; RUN: -passes='loop-mssa(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
33 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1
35 ; NB: sort -b is essential here and below, otherwise blanks might lead to different
36 ; order depending on locale.
38 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
39 ; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=2 \
40 ; RUN: -passes='loop(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
41 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2
43 ; RUN: opt < %s -enable-unswitch-cost-multiplier=true \
44 ; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=2 \
45 ; RUN: -passes='loop-mssa(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
46 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2
49 ; 2^(num conds) == 2^5 = 32
50 ; loop nests when cost multiplier is disabled:
52 ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
53 ; RUN: -passes='loop(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
54 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32
56 ; RUN: opt < %s -enable-unswitch-cost-multiplier=false \
57 ; RUN: -passes='loop-mssa(unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \
58 ; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32
60 ; Single loop nest, not unswitched
61 ; LOOP1: Loop at depth 1 containing:
62 ; LOOP1: Loop at depth 2 containing:
63 ; LOOP1: Loop at depth 3 containing:
64 ; LOOP1-NOT: Loop at depth {{[0-9]+}} containing:
66 ; Half unswitched loop nests, with unscaled4 and div1 it gets less depth1 loops unswitched
67 ; since they have more cost.
68 ; LOOP-UNSCALE4-DIV1-COUNT-6: Loop at depth 1 containing:
69 ; LOOP-UNSCALE4-DIV1-COUNT-19: Loop at depth 2 containing:
70 ; LOOP-UNSCALE4-DIV1-COUNT-29: Loop at depth 3 containing:
71 ; LOOP-UNSCALE4-DIV1-NOT: Loop at depth {{[0-9]+}} containing:
73 ; Half unswitched loop nests, with unscaled4 and div2 it gets more depth1 loops unswitched
75 ; LOOP-UNSCALE4-DIV2-COUNT-11: Loop at depth 1 containing:
76 ; LOOP-UNSCALE4-DIV2-COUNT-22: Loop at depth 2 containing:
77 ; LOOP-UNSCALE4-DIV2-COUNT-29: Loop at depth 3 containing:
78 ; LOOP-UNSCALE4-DIV2-NOT: Loop at depth {{[0-9]+}} containing:
80 ; 32 loop nests, fully unswitched
81 ; LOOP32-COUNT-32: Loop at depth 1 containing:
82 ; LOOP32-COUNT-32: Loop at depth 2 containing:
83 ; LOOP32-COUNT-32: Loop at depth 3 containing:
84 ; LOOP32-NOT: Loop at depth {{[0-9]+}} containing:
88 define void @loop_nested3_conds5(i32* %addr, i1 %c1, i1 %c2, i1 %c3, i1 %c4, i1 %c5) {
90 %addr1 = getelementptr i32, i32* %addr, i64 0
91 %addr2 = getelementptr i32, i32* %addr, i64 1
92 %addr3 = getelementptr i32, i32* %addr, i64 2
95 %iv1 = phi i32 [0, %entry], [%iv1.next, %outer_latch]
96 %iv1.next = add i32 %iv1, 1
97 ;; skip nontrivial unswitch
101 %iv2 = phi i32 [0, %outer], [%iv2.next, %middle_latch]
102 %iv2.next = add i32 %iv2, 1
103 ;; skip nontrivial unswitch
107 %iv3 = phi i32 [0, %middle], [%iv3.next, %loop_latch]
108 %iv3.next = add i32 %iv3, 1
109 ;; skip nontrivial unswitch
111 br i1 %c1, label %loop_next1_left, label %loop_next1_right
118 br i1 %c2, label %loop_next2_left, label %loop_next2_right
125 br i1 %c3, label %loop_next3_left, label %loop_next3_right
132 br i1 %c4, label %loop_next4_left, label %loop_next4_right
139 br i1 %c5, label %loop_latch_left, label %loop_latch_right
146 store volatile i32 0, i32* %addr1
147 %test_loop = icmp slt i32 %iv3, 50
148 br i1 %test_loop, label %loop, label %middle_latch
150 store volatile i32 0, i32* %addr2
151 %test_middle = icmp slt i32 %iv2, 50
152 br i1 %test_middle, label %middle, label %outer_latch
154 store volatile i32 0, i32* %addr3
155 %test_outer = icmp slt i32 %iv1, 50
156 br i1 %test_outer, label %outer, label %exit