1; RUN: opt -S < %s -passes='print<scalar-evolution>,loop-simplify,print<scalar-evolution>' 2>&1 | FileCheck %s 2 3; Provide legal integer types. 4target datalayout = "n8:16:32:64" 5 6@maxStat = external global i32 7 8; LoopSimplify should invalidate SCEV when splitting out the 9; inner loop. 10; 11; First SCEV print: 12; CHECK-LABEL: Classifying expressions for: @test 13; CHECK: %[[PHI:.*]] = phi i32 [ 0, %entry ], [ %{{.*}}, %if.then5 ], [ %[[PHI]], %if.end ] 14; CHECK-LABEL: Determining loop execution counts for: @test 15; CHECK: Loop %for.body18: Unpredictable backedge-taken count. 16; CHECK: Loop %for.body18: constant max backedge-taken count is i32 2147483646 17; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count. 18; CHECK: Loop %for.cond: Unpredictable constant max backedge-taken count. 19; 20; Now simplify the loop, which should cause SCEV to re-compute more precise 21; info here in addition to having preheader PHIs. Second SCEV print: 22; CHECK-LABEL: Classifying expressions for: @test 23; CHECK: phi i32 [ %{{.*}}, %if.then5 ], [ 0, %entry ] 24; CHECK-LABEL: Determining loop execution counts for: @test 25; CHECK: Loop %for.body18: Unpredictable backedge-taken count. 26; CHECK: Loop %for.body18: constant max backedge-taken count is i32 2147483646 27; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count. 28; CHECK: Loop %for.cond: constant max backedge-taken count is i32 -2147483647 29; CHECK: Loop %for.cond.outer: <multiple exits> Unpredictable backedge-taken count. 30; CHECK: Loop %for.cond.outer: Unpredictable constant max backedge-taken count. 31define i32 @test() nounwind { 32entry: 33 br label %for.cond 34 35for.cond: ; preds = %if.then5, %if.end, %entry 36 %cuts.1 = phi i32 [ 0, %entry ], [ %inc, %if.then5 ], [ %cuts.1, %if.end ] 37 %0 = phi i32 [ 0, %entry ], [ %add, %if.end ], [ %add, %if.then5 ] 38 %add = add i32 %0, 1 39 %cmp = icmp slt i32 %0, 1 40 %tmp1 = load i32, ptr @maxStat, align 4 41 br i1 %cmp, label %for.body, label %for.cond14.preheader 42 43for.cond14.preheader: ; preds = %for.cond 44 %cmp1726 = icmp sgt i32 %tmp1, 0 45 br i1 %cmp1726, label %for.body18, label %return 46 47for.body: ; preds = %for.cond 48 %cmp2 = icmp sgt i32 %tmp1, 100 49 br i1 %cmp2, label %return, label %if.end 50 51if.end: ; preds = %for.body 52 %cmp4 = icmp sgt i32 %tmp1, -1 53 br i1 %cmp4, label %if.then5, label %for.cond 54 55if.then5: ; preds = %if.end 56 call void @foo() nounwind 57 %inc = add i32 %cuts.1, 1 58 br label %for.cond 59 60for.body18: ; preds = %for.body18, %for.cond14.preheader 61 %i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ] 62 call void @foo() nounwind 63 %1 = add nsw i32 %i13.027, 1 64 %tmp16 = load i32, ptr @maxStat, align 4 65 %cmp17 = icmp slt i32 %1, %tmp16 66 br i1 %cmp17, label %for.body18, label %return 67 68return: ; preds = %for.body18, %for.body, %for.cond14.preheader 69 ret i32 0 70} 71 72declare void @foo() nounwind 73 74; Notify SCEV when removing an ExitingBlock. This only changes the 75; backedge-taken information. 76; 77; First SCEV print: 78; CHECK-LABEL: Determining loop execution counts for: @mergeExit 79; CHECK: Loop %while.cond191: <multiple exits> Unpredictable backedge-taken count. 80; CHECK: Loop %while.cond191: constant max backedge-taken count is i32 -1 81; CHECK: Loop %while.cond191.outer: <multiple exits> Unpredictable backedge-taken count. 82; CHECK: Loop %while.cond191.outer: Unpredictable constant max backedge-taken count. 83; 84; After simplifying, the max backedge count is refined. 85; Second SCEV print: 86; CHECK-LABEL: Determining loop execution counts for: @mergeExit 87; CHECK: Loop %while.cond191: <multiple exits> backedge-taken count is i32 0 88; CHECK: Loop %while.cond191: constant max backedge-taken count is i32 0 89; CHECK: Loop %while.cond191.outer: <multiple exits> Unpredictable backedge-taken count. 90; CHECK: Loop %while.cond191.outer: constant max backedge-taken count is i1 false 91define void @mergeExit(i32 %MapAttrCount) nounwind uwtable ssp { 92entry: 93 br i1 undef, label %if.then124, label %if.end126 94 95if.then124: ; preds = %entry 96 unreachable 97 98if.end126: ; preds = %entry 99 br i1 undef, label %while.body.lr.ph, label %if.end591 100 101while.body.lr.ph: ; preds = %if.end126 102 br i1 undef, label %if.end140, label %if.then137 103 104if.then137: ; preds = %while.body.lr.ph 105 unreachable 106 107if.end140: ; preds = %while.body.lr.ph 108 br i1 undef, label %while.cond191.outer, label %if.then148 109 110if.then148: ; preds = %if.end140 111 unreachable 112 113while.cond191.outer: ; preds = %if.then205, %if.end140 114 br label %while.cond191 115 116while.cond191: ; preds = %while.body197, %while.cond191.outer 117 %CppIndex.0 = phi i32 [ %inc, %while.body197 ], [ undef, %while.cond191.outer ] 118 br i1 undef, label %land.rhs, label %if.then216 119 120land.rhs: ; preds = %while.cond191 121 %inc = add i32 %CppIndex.0, 1 122 %cmp196 = icmp ult i32 %inc, %MapAttrCount 123 br i1 %cmp196, label %while.body197, label %if.then216 124 125while.body197: ; preds = %land.rhs 126 br i1 undef, label %if.then205, label %while.cond191 127 128if.then205: ; preds = %while.body197 129 br label %while.cond191.outer 130 131if.then216: ; preds = %land.rhs, %while.cond191 132 br i1 undef, label %if.else, label %if.then221 133 134if.then221: ; preds = %if.then216 135 unreachable 136 137if.else: ; preds = %if.then216 138 br i1 undef, label %if.then266, label %if.end340 139 140if.then266: ; preds = %if.else 141 switch i32 undef, label %if.else329 [ 142 i32 17, label %if.then285 143 i32 19, label %if.then285 144 i32 18, label %if.then285 145 i32 15, label %if.then285 146 ] 147 148if.then285: ; preds = %if.then266, %if.then266, %if.then266, %if.then266 149 br i1 undef, label %if.then317, label %if.else324 150 151if.then317: ; preds = %if.then285 152 br label %if.end340 153 154if.else324: ; preds = %if.then285 155 unreachable 156 157if.else329: ; preds = %if.then266 158 unreachable 159 160if.end340: ; preds = %if.then317, %if.else 161 unreachable 162 163if.end591: ; preds = %if.end126 164 br i1 undef, label %cond.end, label %cond.false 165 166cond.false: ; preds = %if.end591 167 unreachable 168 169cond.end: ; preds = %if.end591 170 ret void 171} 172