brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.6 KiB · 72f3c11 Raw
129 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 4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"5 6@A = weak global [1000 x i32] zeroinitializer, align 327 8; The resulting predicate is i16 {0,+,1} <nssw>, meanining9; that the resulting backedge expression will be valid for:10;   (1 + (-1 smax %M)) <= MAX_INT1611;12; At the limit condition for M (MAX_INT16 - 1) we have in the13; last iteration:14;    i0 <- MAX_INT1615;    i0.ext <- MAX_INT1616;17; and therefore no wrapping happend for i0 or i0.ext18; throughout the execution of the loop. The resulting predicated19; backedge taken count is correct.20 21define void @test1(i32 %N, i32 %M) {22; CHECK-LABEL: 'test1'23; CHECK-NEXT:  Classifying expressions for: @test124; CHECK-NEXT:    %tmp = getelementptr [1000 x i32], ptr @A, i32 0, i16 %i.025; CHECK-NEXT:    --> ((4 * (sext i16 {0,+,1}<%bb3> to i64))<nsw> + @A) U: [0,-3) S: [-9223372036854775808,9223372036854775805) Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }26; CHECK-NEXT:    %tmp2 = add i16 %i.0, 127; CHECK-NEXT:    --> {1,+,1}<%bb3> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }28; CHECK-NEXT:    %i.0 = phi i16 [ 0, %entry ], [ %tmp2, %bb ]29; CHECK-NEXT:    --> {0,+,1}<%bb3> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }30; CHECK-NEXT:    %i.0.ext = sext i16 %i.0 to i3231; CHECK-NEXT:    --> (sext i16 {0,+,1}<%bb3> to i32) U: [-32768,32768) S: [-32768,32768) Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }32; CHECK-NEXT:  Determining loop execution counts for: @test133; CHECK-NEXT:  Loop %bb3: Unpredictable backedge-taken count.34; CHECK-NEXT:  Loop %bb3: Unpredictable constant max backedge-taken count.35; CHECK-NEXT:  Loop %bb3: Unpredictable symbolic max backedge-taken count.36; CHECK-NEXT:  Loop %bb3: Predicated backedge-taken count is (1 + (-1 smax %M))37; CHECK-NEXT:   Predicates:38; CHECK-NEXT:      {0,+,1}<%bb3> Added Flags: <nssw>39;40entry:41  br label %bb342 43bb:             ; preds = %bb344  %tmp = getelementptr [1000 x i32], ptr @A, i32 0, i16 %i.0          ; <ptr> [#uses=1]45  store i32 123, ptr %tmp46  %tmp2 = add i16 %i.0, 1         ; <i32> [#uses=1]47  br label %bb348 49bb3:            ; preds = %bb, %entry50  %i.0 = phi i16 [ 0, %entry ], [ %tmp2, %bb ]            ; <i32> [#uses=3]51  %i.0.ext = sext i16 %i.0 to i3252  %tmp3 = icmp sle i32 %i.0.ext, %M          ; <i1> [#uses=1]53  br i1 %tmp3, label %bb, label %bb554 55bb5:            ; preds = %bb356  br label %return57 58return:         ; preds = %bb559  ret void60}61 62; The predicated backedge taken count is:63;    (2 + (zext i16 %Start to i32) + ((-2 + (-1 * (sext i16 %Start to i32)))64;                                     smax (-1 + (-1 * %M)))65;    )66 67; -1 + (-1 * %M) <= (-2 + (-1 * (sext i16 %Start to i32))68; The predicated backedge taken count is 0.69; From the IR, this is correct since we will bail out at the70; first iteration.71 72 73; * -1 + (-1 * %M) > (-2 + (-1 * (sext i16 %Start to i32))74; or: %M < 1 + (sext i16 %Start to i32)75;76; The predicated backedge taken count is 1 + (zext i16 %Start to i32) - %M77;78; If %M >= MIN_INT + 1, this predicated backedge taken count would be correct (even79; without predicates). However, for %M < MIN_INT this would be an infinite loop.80; In these cases, the {%Start,+,-1} <nusw> predicate would be false, as the81; final value of the expression {%Start,+,-1} expression (%M - 1) would not be82; representable as an i16.83 84; There is also a limit case here where the value of %M is MIN_INT. In this case85; we still have an infinite loop, since icmp sge %x, MIN_INT will always return86; true.87 88define void @test2(i32 %N, i32 %M, i16 %Start) {89; CHECK-LABEL: 'test2'90; CHECK-NEXT:  Classifying expressions for: @test291; CHECK-NEXT:    %tmp = getelementptr [1000 x i32], ptr @A, i32 0, i16 %i.092; CHECK-NEXT:    --> ((4 * (sext i16 {%Start,+,-1}<%bb3> to i64))<nsw> + @A) U: [0,-3) S: [-9223372036854775808,9223372036854775805) Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }93; CHECK-NEXT:    %tmp2 = sub i16 %i.0, 194; CHECK-NEXT:    --> {(-1 + %Start),+,-1}<%bb3> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }95; CHECK-NEXT:    %i.0 = phi i16 [ %Start, %entry ], [ %tmp2, %bb ]96; CHECK-NEXT:    --> {%Start,+,-1}<%bb3> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }97; CHECK-NEXT:    %i.0.ext = sext i16 %i.0 to i3298; CHECK-NEXT:    --> (sext i16 {%Start,+,-1}<%bb3> to i32) U: [-32768,32768) S: [-32768,32768) Exits: <<Unknown>> LoopDispositions: { %bb3: Computable }99; CHECK-NEXT:  Determining loop execution counts for: @test2100; CHECK-NEXT:  Loop %bb3: Unpredictable backedge-taken count.101; CHECK-NEXT:  Loop %bb3: Unpredictable constant max backedge-taken count.102; CHECK-NEXT:  Loop %bb3: Unpredictable symbolic max backedge-taken count.103; CHECK-NEXT:  Loop %bb3: Predicated backedge-taken count is (1 + (sext i16 %Start to i32) + (-1 * ((1 + (sext i16 %Start to i32))<nsw> smin %M)))104; CHECK-NEXT:   Predicates:105; CHECK-NEXT:      {%Start,+,-1}<%bb3> Added Flags: <nssw>106;107entry:108  br label %bb3109 110bb:             ; preds = %bb3111  %tmp = getelementptr [1000 x i32], ptr @A, i32 0, i16 %i.0          ; <ptr> [#uses=1]112  store i32 123, ptr %tmp113  %tmp2 = sub i16 %i.0, 1         ; <i32> [#uses=1]114  br label %bb3115 116bb3:            ; preds = %bb, %entry117  %i.0 = phi i16 [ %Start, %entry ], [ %tmp2, %bb ]            ; <i32> [#uses=3]118  %i.0.ext = sext i16 %i.0 to i32119  %tmp3 = icmp sge i32 %i.0.ext, %M          ; <i1> [#uses=1]120  br i1 %tmp3, label %bb, label %bb5121 122bb5:            ; preds = %bb3123  br label %return124 125return:         ; preds = %bb5126  ret void127}128 129