1; 2; There should be just a single copy of each loop when strictest mutiplier 3; candidates formula (unscaled candidates == 0) is enforced: 4 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-mssa(simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 8; 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(simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 12; 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(simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 16; 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(simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | FileCheck %s --check-prefixes=LOOP1 20; 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. 24; 25; The tests below also run licm, because it is needed to hoist out 26; loop-invariant freeze instructions, which otherwise may block further 27; unswitching. 28; 29; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ 30; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=1 \ 31; RUN: -passes='loop-mssa(licm,simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \ 32; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV1 33; 34; NB: sort -b is essential here and below, otherwise blanks might lead to different 35; order depending on locale. 36; 37; RUN: opt < %s -enable-unswitch-cost-multiplier=true \ 38; RUN: -unswitch-num-initial-unscaled-candidates=4 -unswitch-siblings-toplevel-div=2 \ 39; RUN: -passes='loop-mssa(licm,simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \ 40; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP-UNSCALE4-DIV2 41; 42; Get 43; 2^(num conds) == 2^5 = 32 44; loop nests when cost multiplier is disabled: 45; 46; RUN: opt < %s -enable-unswitch-cost-multiplier=false \ 47; RUN: -passes='loop-mssa(licm,simple-loop-unswitch<nontrivial>),print<loops>' -disable-output 2>&1 | \ 48; RUN: sort -b -k 1 | FileCheck %s --check-prefixes=LOOP32 49; 50; Single loop nest, not unswitched 51; LOOP1: Loop at depth 1 containing: 52; LOOP1: Loop at depth 2 containing: 53; LOOP1: Loop at depth 3 containing: 54; LOOP1-NOT: Loop at depth {{[0-9]+}} containing: 55; 56; Half unswitched loop nests, with unscaled4 and div1 it gets less depth1 loops unswitched 57; since they have more cost. 58; LOOP-UNSCALE4-DIV1-COUNT-6: Loop at depth 1 containing: 59; LOOP-UNSCALE4-DIV1-COUNT-19: Loop at depth 2 containing: 60; LOOP-UNSCALE4-DIV1-COUNT-29: Loop at depth 3 containing: 61; LOOP-UNSCALE4-DIV1-NOT: Loop at depth {{[0-9]+}} containing: 62; 63; Half unswitched loop nests, with unscaled4 and div2 it gets more depth1 loops unswitched 64; as div2 kicks in. 65; LOOP-UNSCALE4-DIV2-COUNT-11: Loop at depth 1 containing: 66; LOOP-UNSCALE4-DIV2-COUNT-22: Loop at depth 2 containing: 67; LOOP-UNSCALE4-DIV2-COUNT-29: Loop at depth 3 containing: 68; LOOP-UNSCALE4-DIV2-NOT: Loop at depth {{[0-9]+}} containing: 69; 70; 32 loop nests, fully unswitched 71; LOOP32-COUNT-32: Loop at depth 1 containing: 72; LOOP32-COUNT-32: Loop at depth 2 containing: 73; LOOP32-COUNT-32: Loop at depth 3 containing: 74; LOOP32-NOT: Loop at depth {{[0-9]+}} containing: 75 76declare void @bar() 77 78define void @loop_nested3_conds5(ptr %addr, i1 %c1, i1 %c2, i1 %c3, i1 %c4, i1 %c5) { 79entry: 80 %addr2 = getelementptr i32, ptr %addr, i64 1 81 %addr3 = getelementptr i32, ptr %addr, i64 2 82 br label %outer 83outer: 84 %iv1 = phi i32 [0, %entry], [%iv1.next, %outer_latch] 85 %iv1.next = add i32 %iv1, 1 86 ;; skip nontrivial unswitch 87 call void @bar() 88 br label %middle 89middle: 90 %iv2 = phi i32 [0, %outer], [%iv2.next, %middle_latch] 91 %iv2.next = add i32 %iv2, 1 92 ;; skip nontrivial unswitch 93 call void @bar() 94 br label %loop 95loop: 96 %iv3 = phi i32 [0, %middle], [%iv3.next, %loop_latch] 97 %iv3.next = add i32 %iv3, 1 98 ;; skip nontrivial unswitch 99 call void @bar() 100 br i1 %c1, label %loop_next1_left, label %loop_next1_right 101loop_next1_left: 102 br label %loop_next1 103loop_next1_right: 104 br label %loop_next1 105 106loop_next1: 107 br i1 %c2, label %loop_next2_left, label %loop_next2_right 108loop_next2_left: 109 br label %loop_next2 110loop_next2_right: 111 br label %loop_next2 112 113loop_next2: 114 br i1 %c3, label %loop_next3_left, label %loop_next3_right 115loop_next3_left: 116 br label %loop_next3 117loop_next3_right: 118 br label %loop_next3 119 120loop_next3: 121 br i1 %c4, label %loop_next4_left, label %loop_next4_right 122loop_next4_left: 123 br label %loop_next4 124loop_next4_right: 125 br label %loop_next4 126 127loop_next4: 128 br i1 %c5, label %loop_latch_left, label %loop_latch_right 129loop_latch_left: 130 br label %loop_latch 131loop_latch_right: 132 br label %loop_latch 133 134loop_latch: 135 store volatile i32 0, ptr %addr 136 %test_loop = icmp slt i32 %iv3, 50 137 br i1 %test_loop, label %loop, label %middle_latch 138middle_latch: 139 store volatile i32 0, ptr %addr2 140 %test_middle = icmp slt i32 %iv2, 50 141 br i1 %test_middle, label %middle, label %outer_latch 142outer_latch: 143 store volatile i32 0, ptr %addr3 144 %test_outer = icmp slt i32 %iv1, 50 145 br i1 %test_outer, label %outer, label %exit 146exit: 147 ret void 148} 149