172 lines · plain
1; RUN: opt -S < %s -passes='print<scalar-evolution>,loop-simplify,print<scalar-evolution>' 2>&1 | FileCheck %s2 3; Provide legal integer types.4target datalayout = "n8:16:32:64"5 6@maxStat = external global i327 8; LoopSimplify should invalidate SCEV when splitting out the9; inner loop.10;11; First SCEV print:12; CHECK-LABEL: Classifying expressions for: @test13; CHECK: %[[PHI:.*]] = phi i32 [ 0, %entry ], [ %{{.*}}, %if.then5 ], [ %[[PHI]], %if.end ]14; CHECK-LABEL: Determining loop execution counts for: @test15; CHECK: Loop %for.body18: Unpredictable backedge-taken count.16; CHECK: Loop %for.body18: constant max backedge-taken count is i32 214748364617; 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 precise21; info here in addition to having preheader PHIs. Second SCEV print:22; CHECK-LABEL: Classifying expressions for: @test23; CHECK: phi i32 [ %{{.*}}, %if.then5 ], [ 0, %entry ]24; CHECK-LABEL: Determining loop execution counts for: @test25; CHECK: Loop %for.body18: Unpredictable backedge-taken count.26; CHECK: Loop %for.body18: constant max backedge-taken count is i32 214748364627; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count.28; CHECK: Loop %for.cond: constant max backedge-taken count is i32 -214748364729; 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.cond34 35for.cond: ; preds = %if.then5, %if.end, %entry36 %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, 139 %cmp = icmp slt i32 %0, 140 %tmp1 = load i32, ptr @maxStat, align 441 br i1 %cmp, label %for.body, label %for.cond14.preheader42 43for.cond14.preheader: ; preds = %for.cond44 %cmp1726 = icmp sgt i32 %tmp1, 045 br i1 %cmp1726, label %for.body18, label %return46 47for.body: ; preds = %for.cond48 %cmp2 = icmp sgt i32 %tmp1, 10049 br i1 %cmp2, label %return, label %if.end50 51if.end: ; preds = %for.body52 %cmp4 = icmp sgt i32 %tmp1, -153 br i1 %cmp4, label %if.then5, label %for.cond54 55if.then5: ; preds = %if.end56 call void @foo() nounwind57 %inc = add i32 %cuts.1, 158 br label %for.cond59 60for.body18: ; preds = %for.body18, %for.cond14.preheader61 %i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ]62 call void @foo() nounwind63 %1 = add nsw i32 %i13.027, 164 %tmp16 = load i32, ptr @maxStat, align 465 %cmp17 = icmp slt i32 %1, %tmp1666 br i1 %cmp17, label %for.body18, label %return67 68return: ; preds = %for.body18, %for.body, %for.cond14.preheader69 ret i32 070}71 72declare void @foo() nounwind73 74; Notify SCEV when removing an ExitingBlock. This only changes the75; backedge-taken information.76;77; First SCEV print:78; CHECK-LABEL: Determining loop execution counts for: @mergeExit79; CHECK: Loop %while.cond191: <multiple exits> Unpredictable backedge-taken count.80; CHECK: Loop %while.cond191: constant max backedge-taken count is i32 -181; 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: @mergeExit87; CHECK: Loop %while.cond191: <multiple exits> backedge-taken count is i32 088; CHECK: Loop %while.cond191: constant max backedge-taken count is i32 089; CHECK: Loop %while.cond191.outer: <multiple exits> Unpredictable backedge-taken count.90; CHECK: Loop %while.cond191.outer: constant max backedge-taken count is i1 false91define void @mergeExit(i32 %MapAttrCount) nounwind uwtable ssp {92entry:93 br i1 undef, label %if.then124, label %if.end12694 95if.then124: ; preds = %entry96 unreachable97 98if.end126: ; preds = %entry99 br i1 undef, label %while.body.lr.ph, label %if.end591100 101while.body.lr.ph: ; preds = %if.end126102 br i1 undef, label %if.end140, label %if.then137103 104if.then137: ; preds = %while.body.lr.ph105 unreachable106 107if.end140: ; preds = %while.body.lr.ph108 br i1 undef, label %while.cond191.outer, label %if.then148109 110if.then148: ; preds = %if.end140111 unreachable112 113while.cond191.outer: ; preds = %if.then205, %if.end140114 br label %while.cond191115 116while.cond191: ; preds = %while.body197, %while.cond191.outer117 %CppIndex.0 = phi i32 [ %inc, %while.body197 ], [ undef, %while.cond191.outer ]118 br i1 undef, label %land.rhs, label %if.then216119 120land.rhs: ; preds = %while.cond191121 %inc = add i32 %CppIndex.0, 1122 %cmp196 = icmp ult i32 %inc, %MapAttrCount123 br i1 %cmp196, label %while.body197, label %if.then216124 125while.body197: ; preds = %land.rhs126 br i1 undef, label %if.then205, label %while.cond191127 128if.then205: ; preds = %while.body197129 br label %while.cond191.outer130 131if.then216: ; preds = %land.rhs, %while.cond191132 br i1 undef, label %if.else, label %if.then221133 134if.then221: ; preds = %if.then216135 unreachable136 137if.else: ; preds = %if.then216138 br i1 undef, label %if.then266, label %if.end340139 140if.then266: ; preds = %if.else141 switch i32 undef, label %if.else329 [142 i32 17, label %if.then285143 i32 19, label %if.then285144 i32 18, label %if.then285145 i32 15, label %if.then285146 ]147 148if.then285: ; preds = %if.then266, %if.then266, %if.then266, %if.then266149 br i1 undef, label %if.then317, label %if.else324150 151if.then317: ; preds = %if.then285152 br label %if.end340153 154if.else324: ; preds = %if.then285155 unreachable156 157if.else329: ; preds = %if.then266158 unreachable159 160if.end340: ; preds = %if.then317, %if.else161 unreachable162 163if.end591: ; preds = %if.end126164 br i1 undef, label %cond.end, label %cond.false165 166cond.false: ; preds = %if.end591167 unreachable168 169cond.end: ; preds = %if.end591170 ret void171}172