brintos

brintos / llvm-project-archived public Read only

0
0
Text · 23.8 KiB · 4d668d1 Raw
458 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py2; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s3 4; The addrecs in this loop are analyzable only by using nsw information.5 6target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64"7 8define void @test1(ptr %p) nounwind {9; CHECK-LABEL: 'test1'10; CHECK-NEXT:  Classifying expressions for: @test111; CHECK-NEXT:    %i.01 = phi i32 [ %tmp8, %bb1 ], [ 0, %bb.nph ]12; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%bb> U: [0,-2147483648) S: [0,-2147483648) Exits: <<Unknown>> LoopDispositions: { %bb: Computable }13; CHECK-NEXT:    %tmp2 = sext i32 %i.01 to i6414; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%bb> U: [0,-9223372036854775808) S: [0,-9223372036854775808) Exits: <<Unknown>> LoopDispositions: { %bb: Computable }15; CHECK-NEXT:    %tmp3 = getelementptr double, ptr %p, i64 %tmp216; CHECK-NEXT:    --> {%p,+,8}<%bb> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb: Computable }17; CHECK-NEXT:    %tmp6 = sext i32 %i.01 to i6418; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%bb> U: [0,-9223372036854775808) S: [0,-9223372036854775808) Exits: <<Unknown>> LoopDispositions: { %bb: Computable }19; CHECK-NEXT:    %tmp7 = getelementptr double, ptr %p, i64 %tmp620; CHECK-NEXT:    --> {%p,+,8}<%bb> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb: Computable }21; CHECK-NEXT:    %tmp8 = add nsw i32 %i.01, 122; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%bb> U: [1,-2147483648) S: [1,-2147483648) Exits: <<Unknown>> LoopDispositions: { %bb: Computable }23; CHECK-NEXT:    %p.gep = getelementptr double, ptr %p, i32 %tmp824; CHECK-NEXT:    --> {(8 + %p),+,8}<%bb> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb: Computable }25; CHECK-NEXT:    %phitmp = sext i32 %tmp8 to i6426; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%bb> U: [1,-9223372036854775808) S: [1,-9223372036854775808) Exits: <<Unknown>> LoopDispositions: { %bb: Computable }27; CHECK-NEXT:    %tmp9 = getelementptr inbounds double, ptr %p, i64 %phitmp28; CHECK-NEXT:    --> {(8 + %p),+,8}<%bb> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb: Computable }29; CHECK-NEXT:  Determining loop execution counts for: @test130; CHECK-NEXT:  Loop %bb: Unpredictable backedge-taken count.31; CHECK-NEXT:  Loop %bb: Unpredictable constant max backedge-taken count.32; CHECK-NEXT:  Loop %bb: Unpredictable symbolic max backedge-taken count.33;34entry:35  %tmp = load double, ptr %p, align 8		; <double> [#uses=1]36  %tmp1 = fcmp ogt double %tmp, 2.000000e+00		; <i1> [#uses=1]37  br i1 %tmp1, label %bb.nph, label %return38 39bb.nph:		; preds = %entry40  br label %bb41 42bb:		; preds = %bb1, %bb.nph43  %i.01 = phi i32 [ %tmp8, %bb1 ], [ 0, %bb.nph ]		; <i32> [#uses=3]44  %tmp2 = sext i32 %i.01 to i64		; <i64> [#uses=1]45  %tmp3 = getelementptr double, ptr %p, i64 %tmp2		; <ptr> [#uses=1]46  %tmp4 = load double, ptr %tmp3, align 8		; <double> [#uses=1]47  %tmp5 = fmul double %tmp4, 9.200000e+00		; <double> [#uses=1]48  %tmp6 = sext i32 %i.01 to i64		; <i64> [#uses=1]49  %tmp7 = getelementptr double, ptr %p, i64 %tmp6		; <ptr> [#uses=1]50  store double %tmp5, ptr %tmp7, align 851  %tmp8 = add nsw i32 %i.01, 1		; <i32> [#uses=2]52  %p.gep = getelementptr double, ptr %p, i32 %tmp853  %p.val = load double, ptr %p.gep54  br label %bb155 56bb1:		; preds = %bb57  %phitmp = sext i32 %tmp8 to i64		; <i64> [#uses=1]58  %tmp9 = getelementptr inbounds double, ptr %p, i64 %phitmp		; <ptr> [#uses=1]59  %tmp10 = load double, ptr %tmp9, align 8		; <double> [#uses=1]60  %tmp11 = fcmp ogt double %tmp10, 2.000000e+00		; <i1> [#uses=1]61  br i1 %tmp11, label %bb, label %bb1.return_crit_edge62 63bb1.return_crit_edge:		; preds = %bb164  br label %return65 66return:		; preds = %bb1.return_crit_edge, %entry67  ret void68}69 70define void @test2(ptr %begin, ptr %end) ssp {71; CHECK-LABEL: 'test2'72; CHECK-NEXT:  Classifying expressions for: @test273; CHECK-NEXT:    %__first.addr.02.i.i = phi ptr [ %begin, %for.body.lr.ph.i.i ], [ %ptrincdec.i.i, %for.body.i.i ]74; CHECK-NEXT:    --> {%begin,+,4}<nuw><%for.body.i.i> U: full-set S: full-set Exits: ((4 * ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4))<nuw> + %begin) LoopDispositions: { %for.body.i.i: Computable }75; CHECK-NEXT:    %ptrincdec.i.i = getelementptr inbounds i32, ptr %__first.addr.02.i.i, i64 176; CHECK-NEXT:    --> {(4 + %begin),+,4}<nuw><%for.body.i.i> U: full-set S: full-set Exits: (4 + (4 * ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4))<nuw> + %begin) LoopDispositions: { %for.body.i.i: Computable }77; CHECK-NEXT:  Determining loop execution counts for: @test278; CHECK-NEXT:  Loop %for.body.i.i: backedge-taken count is ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4)79; CHECK-NEXT:  Loop %for.body.i.i: constant max backedge-taken count is i64 461168601842738790380; CHECK-NEXT:  Loop %for.body.i.i: symbolic max backedge-taken count is ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4)81; CHECK-NEXT:  Loop %for.body.i.i: Trip multiple is 182;83entry:84  %cmp1.i.i = icmp eq ptr %begin, %end85  br i1 %cmp1.i.i, label %_ZSt4fillIPiiEvT_S1_RKT0_.exit, label %for.body.lr.ph.i.i86 87for.body.lr.ph.i.i:                               ; preds = %entry88  br label %for.body.i.i89 90for.body.i.i:                                     ; preds = %for.body.i.i, %for.body.lr.ph.i.i91  %__first.addr.02.i.i = phi ptr [ %begin, %for.body.lr.ph.i.i ], [ %ptrincdec.i.i, %for.body.i.i ]92  store i32 0, ptr %__first.addr.02.i.i, align 493  %ptrincdec.i.i = getelementptr inbounds i32, ptr %__first.addr.02.i.i, i64 194  %cmp.i.i = icmp eq ptr %ptrincdec.i.i, %end95  br i1 %cmp.i.i, label %for.cond.for.end_crit_edge.i.i, label %for.body.i.i96 97for.cond.for.end_crit_edge.i.i:                   ; preds = %for.body.i.i98  br label %_ZSt4fillIPiiEvT_S1_RKT0_.exit99 100_ZSt4fillIPiiEvT_S1_RKT0_.exit:                   ; preds = %entry, %for.cond.for.end_crit_edge.i.i101  ret void102}103 104; Various checks for inbounds geps.105define void @test3(ptr %begin, ptr %end) nounwind ssp {106; CHECK-LABEL: 'test3'107; CHECK-NEXT:  Classifying expressions for: @test3108; CHECK-NEXT:    %indvar.i.i = phi i64 [ %tmp, %for.body.i.i ], [ 0, %entry ]109; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body.i.i> U: [0,4611686018427387904) S: [0,4611686018427387904) Exits: ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4) LoopDispositions: { %for.body.i.i: Computable }110; CHECK-NEXT:    %tmp = add nsw i64 %indvar.i.i, 1111; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body.i.i> U: [1,4611686018427387905) S: [1,4611686018427387905) Exits: (1 + ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4))<nuw><nsw> LoopDispositions: { %for.body.i.i: Computable }112; CHECK-NEXT:    %ptrincdec.i.i = getelementptr inbounds i32, ptr %begin, i64 %tmp113; CHECK-NEXT:    --> {(4 + %begin),+,4}<nuw><%for.body.i.i> U: full-set S: full-set Exits: (4 + (4 * ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4))<nuw> + %begin) LoopDispositions: { %for.body.i.i: Computable }114; CHECK-NEXT:    %__first.addr.08.i.i = getelementptr inbounds i32, ptr %begin, i64 %indvar.i.i115; CHECK-NEXT:    --> {%begin,+,4}<nuw><%for.body.i.i> U: full-set S: full-set Exits: ((4 * ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4))<nuw> + %begin) LoopDispositions: { %for.body.i.i: Computable }116; CHECK-NEXT:  Determining loop execution counts for: @test3117; CHECK-NEXT:  Loop %for.body.i.i: backedge-taken count is ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4)118; CHECK-NEXT:  Loop %for.body.i.i: constant max backedge-taken count is i64 4611686018427387903119; CHECK-NEXT:  Loop %for.body.i.i: symbolic max backedge-taken count is ((-4 + (-1 * (ptrtoint ptr %begin to i64)) + (ptrtoint ptr %end to i64)) /u 4)120; CHECK-NEXT:  Loop %for.body.i.i: Trip multiple is 1121;122entry:123  %cmp7.i.i = icmp eq ptr %begin, %end124  br i1 %cmp7.i.i, label %_ZSt4fillIPiiEvT_S1_RKT0_.exit, label %for.body.i.i125 126for.body.i.i:                                     ; preds = %entry, %for.body.i.i127  %indvar.i.i = phi i64 [ %tmp, %for.body.i.i ], [ 0, %entry ]128  %tmp = add nsw i64 %indvar.i.i, 1129  %ptrincdec.i.i = getelementptr inbounds i32, ptr %begin, i64 %tmp130  %__first.addr.08.i.i = getelementptr inbounds i32, ptr %begin, i64 %indvar.i.i131  store i32 0, ptr %__first.addr.08.i.i, align 4132  %cmp.i.i = icmp eq ptr %ptrincdec.i.i, %end133  br i1 %cmp.i.i, label %_ZSt4fillIPiiEvT_S1_RKT0_.exit, label %for.body.i.i134_ZSt4fillIPiiEvT_S1_RKT0_.exit:                   ; preds = %for.body.i.i, %entry135  ret void136}137 138; A single AddExpr exists for (%a + %b), which is not always <nsw>.139define i32 @addnsw(i32 %a, i32 %b) nounwind ssp {140; CHECK-LABEL: 'addnsw'141; CHECK-NEXT:  Classifying expressions for: @addnsw142; CHECK-NEXT:    %tmp = add i32 %a, %b143; CHECK-NEXT:    --> (%a + %b) U: full-set S: full-set144; CHECK-NEXT:    %tmp2 = add nsw i32 %a, %b145; CHECK-NEXT:    --> (%a + %b) U: full-set S: full-set146; CHECK-NEXT:    %result = phi i32 [ %a, %entry ], [ %tmp2, %greater ]147; CHECK-NEXT:    --> %result U: full-set S: full-set148; CHECK-NEXT:  Determining loop execution counts for: @addnsw149;150entry:151  %tmp = add i32 %a, %b152  %cmp = icmp sgt i32 %tmp, 0153  br i1 %cmp, label %greater, label %exit154 155greater:156  %tmp2 = add nsw i32 %a, %b157  br label %exit158 159exit:160  %result = phi i32 [ %a, %entry ], [ %tmp2, %greater ]161  ret i32 %result162}163 164define i32 @PR12375(ptr readnone %arg) {165; CHECK-LABEL: 'PR12375'166; CHECK-NEXT:  Classifying expressions for: @PR12375167; CHECK-NEXT:    %tmp = getelementptr inbounds i32, ptr %arg, i64 2168; CHECK-NEXT:    --> (8 + %arg)<nuw> U: [8,0) S: [8,0)169; CHECK-NEXT:    %tmp2 = phi ptr [ %arg, %bb ], [ %tmp5, %bb1 ]170; CHECK-NEXT:    --> {%arg,+,4}<nuw><%bb1> U: full-set S: full-set Exits: (4 + %arg)<nuw> LoopDispositions: { %bb1: Computable }171; CHECK-NEXT:    %tmp3 = phi i32 [ 0, %bb ], [ %tmp4, %bb1 ]172; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%bb1> U: [0,2) S: [0,2) Exits: 1 LoopDispositions: { %bb1: Computable }173; CHECK-NEXT:    %tmp4 = add nsw i32 %tmp3, 1174; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%bb1> U: [1,3) S: [1,3) Exits: 2 LoopDispositions: { %bb1: Computable }175; CHECK-NEXT:    %tmp5 = getelementptr inbounds i32, ptr %tmp2, i64 1176; CHECK-NEXT:    --> {(4 + %arg)<nuw>,+,4}<nuw><%bb1> U: [4,0) S: [4,0) Exits: (8 + %arg)<nuw> LoopDispositions: { %bb1: Computable }177; CHECK-NEXT:  Determining loop execution counts for: @PR12375178; CHECK-NEXT:  Loop %bb1: backedge-taken count is i64 1179; CHECK-NEXT:  Loop %bb1: constant max backedge-taken count is i64 1180; CHECK-NEXT:  Loop %bb1: symbolic max backedge-taken count is i64 1181; CHECK-NEXT:  Loop %bb1: Trip multiple is 2182;183bb:184  %tmp = getelementptr inbounds i32, ptr %arg, i64 2185  br label %bb1186 187bb1:                                              ; preds = %bb1, %bb188  %tmp2 = phi ptr [ %arg, %bb ], [ %tmp5, %bb1 ]189  %tmp3 = phi i32 [ 0, %bb ], [ %tmp4, %bb1 ]190  %tmp4 = add nsw i32 %tmp3, 1191  %tmp5 = getelementptr inbounds i32, ptr %tmp2, i64 1192  %tmp6 = icmp ult ptr %tmp5, %tmp193  br i1 %tmp6, label %bb1, label %bb7194 195bb7:                                              ; preds = %bb1196  ret i32 %tmp4197}198 199define void @PR12376(ptr nocapture %arg, ptr nocapture %arg1)  {200; CHECK-LABEL: 'PR12376'201; CHECK-NEXT:  Classifying expressions for: @PR12376202; CHECK-NEXT:    %tmp = phi ptr [ %arg, %bb ], [ %tmp4, %bb2 ]203; CHECK-NEXT:    --> {%arg,+,4}<nuw><%bb2> U: full-set S: full-set Exits: ((4 * ((-1 + (-1 * (ptrtoint ptr %arg to i64)) + ((4 + (ptrtoint ptr %arg to i64))<nuw> umax (ptrtoint ptr %arg1 to i64))) /u 4))<nuw> + %arg) LoopDispositions: { %bb2: Computable }204; CHECK-NEXT:    %tmp4 = getelementptr inbounds i32, ptr %tmp, i64 1205; CHECK-NEXT:    --> {(4 + %arg)<nuw>,+,4}<nuw><%bb2> U: [4,0) S: [4,0) Exits: (4 + (4 * ((-1 + (-1 * (ptrtoint ptr %arg to i64)) + ((4 + (ptrtoint ptr %arg to i64))<nuw> umax (ptrtoint ptr %arg1 to i64))) /u 4))<nuw> + %arg) LoopDispositions: { %bb2: Computable }206; CHECK-NEXT:  Determining loop execution counts for: @PR12376207; CHECK-NEXT:  Loop %bb2: backedge-taken count is ((-1 + (-1 * (ptrtoint ptr %arg to i64)) + ((4 + (ptrtoint ptr %arg to i64))<nuw> umax (ptrtoint ptr %arg1 to i64))) /u 4)208; CHECK-NEXT:  Loop %bb2: constant max backedge-taken count is i64 4611686018427387902209; CHECK-NEXT:  Loop %bb2: symbolic max backedge-taken count is ((-1 + (-1 * (ptrtoint ptr %arg to i64)) + ((4 + (ptrtoint ptr %arg to i64))<nuw> umax (ptrtoint ptr %arg1 to i64))) /u 4)210; CHECK-NEXT:  Loop %bb2: Trip multiple is 1211;212bb:213  br label %bb2214 215bb2:                                              ; preds = %bb2, %bb216  %tmp = phi ptr [ %arg, %bb ], [ %tmp4, %bb2 ]217  %tmp4 = getelementptr inbounds i32, ptr %tmp, i64 1218  %tmp3 = icmp ult ptr %tmp4, %arg1219  br i1 %tmp3, label %bb2, label %bb5220 221bb5:                                              ; preds = %bb2222  ret void223}224 225declare void @f(i32)226 227define void @nswnowrap(i32 %v, ptr %buf) {228; CHECK-LABEL: 'nswnowrap'229; CHECK-NEXT:  Classifying expressions for: @nswnowrap230; CHECK-NEXT:    %add = add nsw i32 %v, 1231; CHECK-NEXT:    --> (1 + %v) U: full-set S: full-set232; CHECK-NEXT:    %i.04 = phi i32 [ %v, %entry ], [ %inc, %for.body ]233; CHECK-NEXT:    --> {%v,+,1}<nsw><%for.body> U: full-set S: full-set Exits: ((1 + %v) smax %v) LoopDispositions: { %for.body: Computable }234; CHECK-NEXT:    %inc = add nsw i32 %i.04, 1235; CHECK-NEXT:    --> {(1 + %v)<nsw>,+,1}<nsw><%for.body> U: full-set S: full-set Exits: (1 + ((1 + %v)<nsw> smax %v)) LoopDispositions: { %for.body: Computable }236; CHECK-NEXT:    %buf.gep = getelementptr inbounds i32, ptr %buf, i32 %inc237; CHECK-NEXT:    --> {(4 + (4 * (sext i32 %v to i64))<nsw> + %buf),+,4}<nw><%for.body> U: full-set S: full-set Exits: (4 + (4 * (zext i32 ((-1 * %v) + ((1 + %v)<nsw> smax %v)) to i64))<nuw><nsw> + (4 * (sext i32 %v to i64))<nsw> + %buf) LoopDispositions: { %for.body: Computable }238; CHECK-NEXT:    %buf.val = load i32, ptr %buf.gep, align 4239; CHECK-NEXT:    --> %buf.val U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Variant }240; CHECK-NEXT:  Determining loop execution counts for: @nswnowrap241; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((-1 * %v) + ((1 + %v)<nsw> smax %v))242; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 1, actual taken count either this or zero.243; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is ((-1 * %v) + ((1 + %v)<nsw> smax %v)), actual taken count either this or zero.244; CHECK-NEXT:  Loop %for.body: Trip multiple is 1245;246entry:247  %add = add nsw i32 %v, 1248  br label %for.body249 250for.body:251  %i.04 = phi i32 [ %v, %entry ], [ %inc, %for.body ]252  %inc = add nsw i32 %i.04, 1253  %buf.gep = getelementptr inbounds i32, ptr %buf, i32 %inc254  %buf.val = load i32, ptr %buf.gep255  %cmp = icmp slt i32 %i.04, %add256  tail call void @f(i32 %i.04)257  br i1 %cmp, label %for.body, label %for.end258 259for.end:260  ret void261}262 263; This test checks if no-wrap flags are propagated when folding {S,+,X}+T ==> {S+T,+,X}264define void @test4(i32 %arg) {265; CHECK-LABEL: 'test4'266; CHECK-NEXT:  Classifying expressions for: @test4267; CHECK-NEXT:    %array = alloca [10 x i32], align 4268; CHECK-NEXT:    --> %array U: [4,-43) S: [-9223372036854775808,9223372036854775805)269; CHECK-NEXT:    %index = phi i32 [ %inc5, %for.body ], [ %arg, %entry ]270; CHECK-NEXT:    --> {%arg,+,1}<nsw><%for.body> U: full-set S: full-set Exits: (-1 + (10 smax (1 + %arg)<nsw>))<nsw> LoopDispositions: { %for.body: Computable }271; CHECK-NEXT:    %sub = add nsw i32 %index, -2272; CHECK-NEXT:    --> {(-2 + %arg)<nsw>,+,1}<nsw><%for.body> U: full-set S: full-set Exits: (-3 + (10 smax (1 + %arg)<nsw>))<nsw> LoopDispositions: { %for.body: Computable }273; CHECK-NEXT:    %idxprom = sext i32 %sub to i64274; CHECK-NEXT:    --> {(-2 + (sext i32 %arg to i64))<nsw>,+,1}<nsw><%for.body> U: [-2147483650,4294967303) S: [-2147483650,4294967303) Exits: (-2 + (zext i32 (-1 + (-1 * %arg) + (10 smax (1 + %arg)<nsw>)) to i64) + (sext i32 %arg to i64)) LoopDispositions: { %for.body: Computable }275; CHECK-NEXT:    %arrayidx = getelementptr inbounds [10 x i32], ptr %array, i64 0, i64 %idxprom276; CHECK-NEXT:    --> {(-8 + (4 * (sext i32 %arg to i64))<nsw> + %array),+,4}<nw><%for.body> U: [0,-3) S: [-9223372036854775808,9223372036854775805) Exits: (-8 + (4 * (zext i32 (-1 + (-1 * %arg) + (10 smax (1 + %arg)<nsw>)) to i64))<nuw><nsw> + (4 * (sext i32 %arg to i64))<nsw> + %array) LoopDispositions: { %for.body: Computable }277; CHECK-NEXT:    %data = load i32, ptr %arrayidx, align 4278; CHECK-NEXT:    --> %data U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Variant }279; CHECK-NEXT:    %inc5 = add nsw i32 %index, 1280; CHECK-NEXT:    --> {(1 + %arg)<nsw>,+,1}<nsw><%for.body> U: [-2147483647,-2147483648) S: [-2147483647,-2147483648) Exits: (10 smax (1 + %arg)<nsw>) LoopDispositions: { %for.body: Computable }281; CHECK-NEXT:  Determining loop execution counts for: @test4282; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + (-1 * %arg) + (10 smax (1 + %arg)<nsw>))283; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i32 -2147483639284; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + (-1 * %arg) + (10 smax (1 + %arg)<nsw>))285; CHECK-NEXT:  Loop %for.body: Trip multiple is 1286;287entry:288  %array = alloca [10 x i32], align 4289  br label %for.body290 291for.body:292  %index = phi i32 [ %inc5, %for.body ], [ %arg, %entry ]293  %sub = add nsw i32 %index, -2294  %idxprom = sext i32 %sub to i64295  %arrayidx = getelementptr inbounds [10 x i32], ptr %array, i64 0, i64 %idxprom296  %data = load i32, ptr %arrayidx, align 4297  %inc5 = add nsw i32 %index, 1298  %cmp2 = icmp slt i32 %inc5, 10299  br i1 %cmp2, label %for.body, label %for.end300 301for.end:302  ret void303}304 305 306define void @bad_postinc_nsw_a(i32 %n) {307; CHECK-LABEL: 'bad_postinc_nsw_a'308; CHECK-NEXT:  Classifying expressions for: @bad_postinc_nsw_a309; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]310; CHECK-NEXT:    --> {0,+,7}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: (7 * ((((-1 * (1 umin %n))<nuw><nsw> + %n) /u 7) + (1 umin %n))) LoopDispositions: { %loop: Computable }311; CHECK-NEXT:    %iv.inc = add nsw i32 %iv, 7312; CHECK-NEXT:    --> {7,+,7}<nuw><%loop> U: [7,-3) S: [7,0) Exits: (7 + (7 * ((((-1 * (1 umin %n))<nuw><nsw> + %n) /u 7) + (1 umin %n)))) LoopDispositions: { %loop: Computable }313; CHECK-NEXT:  Determining loop execution counts for: @bad_postinc_nsw_a314; CHECK-NEXT:  Loop %loop: backedge-taken count is ((((-1 * (1 umin %n))<nuw><nsw> + %n) /u 7) + (1 umin %n))315; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is i32 613566756316; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is ((((-1 * (1 umin %n))<nuw><nsw> + %n) /u 7) + (1 umin %n))317; CHECK-NEXT:  Loop %loop: Trip multiple is 1318;319entry:320  br label %loop321 322loop:323  %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]324  %iv.inc = add nsw i32 %iv, 7325  %becond = icmp ult i32 %iv, %n326  br i1 %becond, label %loop, label %leave327 328leave:329  ret void330}331 332; Unlike @bad_postinc_nsw_a(), the SCEV expression of %iv.inc has <nsw> flag333; because poison can be propagated through 'and %iv.inc, 0'.334define void @postinc_poison_prop_through_and(i32 %n) {335; CHECK-LABEL: 'postinc_poison_prop_through_and'336; CHECK-NEXT:  Classifying expressions for: @postinc_poison_prop_through_and337; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]338; CHECK-NEXT:    --> {0,+,7}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }339; CHECK-NEXT:    %iv.inc = add nsw i32 %iv, 7340; CHECK-NEXT:    --> {7,+,7}<nuw><nsw><%loop> U: [7,-2147483648) S: [7,-2147483648) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }341; CHECK-NEXT:    %iv.inc.and = and i32 %iv.inc, 0342; CHECK-NEXT:    --> 0 U: [0,1) S: [0,1) Exits: 0 LoopDispositions: { %loop: Invariant }343; CHECK-NEXT:  Determining loop execution counts for: @postinc_poison_prop_through_and344; CHECK-NEXT:  Loop %loop: Unpredictable backedge-taken count.345; CHECK-NEXT:  Loop %loop: Unpredictable constant max backedge-taken count.346; CHECK-NEXT:  Loop %loop: Unpredictable symbolic max backedge-taken count.347;348entry:349  br label %loop350 351loop:352  %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]353  %iv.inc = add nsw i32 %iv, 7354  %iv.inc.and = and i32 %iv.inc, 0355  %becond = icmp ult i32 %iv.inc.and, %n356  br i1 %becond, label %loop, label %leave357 358leave:359  ret void360}361 362declare void @may_exit() nounwind363 364define void @pr28012(i32 %n) {365; CHECK-LABEL: 'pr28012'366; CHECK-NEXT:  Classifying expressions for: @pr28012367; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]368; CHECK-NEXT:    --> {0,+,7}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: (7 * ((-1 + (7 umax %n)) /u 7))<nuw> LoopDispositions: { %loop: Computable }369; CHECK-NEXT:    %iv.inc = add nsw i32 %iv, 7370; CHECK-NEXT:    --> {7,+,7}<nuw><%loop> U: [7,-3) S: [7,-3) Exits: (7 + (7 * ((-1 + (7 umax %n)) /u 7))<nuw>) LoopDispositions: { %loop: Computable }371; CHECK-NEXT:  Determining loop execution counts for: @pr28012372; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-1 + (7 umax %n)) /u 7)373; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is i32 613566755374; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is ((-1 + (7 umax %n)) /u 7)375; CHECK-NEXT:  Loop %loop: Trip multiple is 1376;377entry:378  br label %loop379 380loop:381  %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]382  %iv.inc = add nsw i32 %iv, 7383  %becond = icmp ult i32 %iv.inc, %n384  call void @may_exit()385  br i1 %becond, label %loop, label %leave386 387leave:388  ret void389}390 391define void @select_cond_poison_propagation(ptr %p, i32 %x) nounwind {392; CHECK-LABEL: 'select_cond_poison_propagation'393; CHECK-NEXT:  Classifying expressions for: @select_cond_poison_propagation394; CHECK-NEXT:    %iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]395; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }396; CHECK-NEXT:    %iv.next = add nsw i32 %iv, 1397; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,-2147483648) S: [1,-2147483648) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }398; CHECK-NEXT:    %sel = select i1 %cmp, i32 10, i32 20399; CHECK-NEXT:    --> %sel U: [0,31) S: [0,31) Exits: <<Unknown>> LoopDispositions: { %loop: Variant }400; CHECK-NEXT:    %cond = call i1 @cond()401; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }402; CHECK-NEXT:  Determining loop execution counts for: @select_cond_poison_propagation403; CHECK-NEXT:  Loop %loop: Unpredictable backedge-taken count.404; CHECK-NEXT:  Loop %loop: Unpredictable constant max backedge-taken count.405; CHECK-NEXT:  Loop %loop: Unpredictable symbolic max backedge-taken count.406;407entry:408  br label %loop409 410loop:411  %iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]412  %iv.next = add nsw i32 %iv, 1413  %cmp = icmp ult i32 %iv.next, %x414  %sel = select i1 %cmp, i32 10, i32 20415  call void @foo(i32 noundef %sel)416  %cond = call i1 @cond()417  br i1 %cond, label %loop, label %return418 419return:420  ret void421}422 423; {-128,+,-128} should not be <nsw>.424define void @pr66066() {425; CHECK-LABEL: 'pr66066'426; CHECK-NEXT:  Classifying expressions for: @pr66066427; CHECK-NEXT:    %iv = phi i8 [ 1, %entry ], [ %iv.dec, %loop ]428; CHECK-NEXT:    --> {1,+,-1}<nsw><%loop> U: [0,2) S: [0,2) Exits: 0 LoopDispositions: { %loop: Computable }429; CHECK-NEXT:    %iv.dec = add i8 %iv, -1430; CHECK-NEXT:    --> {0,+,-1}<nsw><%loop> U: [-1,1) S: [-1,1) Exits: -1 LoopDispositions: { %loop: Computable }431; CHECK-NEXT:    %shl = shl i8 %iv, 7432; CHECK-NEXT:    --> {-128,+,-128}<%loop> U: [0,-127) S: [-128,1) Exits: 0 LoopDispositions: { %loop: Computable }433; CHECK-NEXT:  Determining loop execution counts for: @pr66066434; CHECK-NEXT:  Loop %loop: backedge-taken count is i8 1435; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is i8 1436; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is i8 1437; CHECK-NEXT:  Loop %loop: Trip multiple is 2438;439entry:440  br label %loop441 442loop:443  %iv = phi i8 [ 1, %entry ], [ %iv.dec, %loop ]444  %iv.dec = add i8 %iv, -1445  %shl = shl i8 %iv, 7446  %cmp1 = icmp eq i8 %shl, 0447  br i1 %cmp1, label %exit, label %loop448 449exit:450  ret void451}452 453declare void @print(i32)454 455declare void @foo(i32)456 457declare i1 @cond()458