xref: /llvm-project/llvm/test/Analysis/ScalarEvolution/nsw-offset-assume.ll (revision 8b5b294ec2cf876bc5eb5bd5fcb56ef487e36d60)
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt < %s -S -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
3
4; ScalarEvolution should be able to fold away the sign-extensions
5; on this loop with a primary induction variable incremented with
6; a nsw add of 2 (this test is derived from the nsw-offset.ll test, but uses an
7; assume instead of a preheader conditional branch to guard the loop).
8
9target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
10
11; Note: Without the preheader assume, there is an 'smax' in the
12; backedge-taken count expression:
13define void @foo(i32 %no, ptr nocapture %d, ptr nocapture %q) nounwind {
14; CHECK-LABEL: 'foo'
15; CHECK-NEXT:  Classifying expressions for: @foo
16; CHECK-NEXT:    %n = and i32 %no, -2
17; CHECK-NEXT:    --> (2 * (%no /u 2))<nuw> U: [0,-1) S: [-2147483648,2147483647)
18; CHECK-NEXT:    %i.01 = phi i32 [ %16, %bb1 ], [ 0, %bb.nph ]
19; CHECK-NEXT:    --> {0,+,2}<nuw><nsw><%bb> U: [0,2147483645) S: [0,2147483645) Exits: (2 * ((-1 + (2 * (%no /u 2))<nuw>) /u 2))<nuw> LoopDispositions: { %bb: Computable }
20; CHECK-NEXT:    %1 = sext i32 %i.01 to i64
21; CHECK-NEXT:    --> {0,+,2}<nuw><nsw><%bb> U: [0,2147483645) S: [0,2147483645) Exits: (2 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> LoopDispositions: { %bb: Computable }
22; CHECK-NEXT:    %2 = getelementptr inbounds double, ptr %d, i64 %1
23; CHECK-NEXT:    --> {%d,+,16}<nuw><%bb> U: full-set S: full-set Exits: ((16 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> + %d) LoopDispositions: { %bb: Computable }
24; CHECK-NEXT:    %4 = sext i32 %i.01 to i64
25; CHECK-NEXT:    --> {0,+,2}<nuw><nsw><%bb> U: [0,2147483645) S: [0,2147483645) Exits: (2 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> LoopDispositions: { %bb: Computable }
26; CHECK-NEXT:    %5 = getelementptr inbounds double, ptr %q, i64 %4
27; CHECK-NEXT:    --> {%q,+,16}<nuw><%bb> U: full-set S: full-set Exits: ((16 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> + %q) LoopDispositions: { %bb: Computable }
28; CHECK-NEXT:    %7 = or disjoint i32 %i.01, 1
29; CHECK-NEXT:    --> {1,+,2}<nuw><nsw><%bb> U: [1,2147483646) S: [1,2147483646) Exits: (1 + (2 * ((-1 + (2 * (%no /u 2))<nuw>) /u 2))<nuw>)<nuw><nsw> LoopDispositions: { %bb: Computable }
30; CHECK-NEXT:    %8 = sext i32 %7 to i64
31; CHECK-NEXT:    --> {1,+,2}<nuw><nsw><%bb> U: [1,2147483646) S: [1,2147483646) Exits: (1 + (2 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw>)<nuw><nsw> LoopDispositions: { %bb: Computable }
32; CHECK-NEXT:    %9 = getelementptr inbounds double, ptr %q, i64 %8
33; CHECK-NEXT:    --> {(8 + %q),+,16}<nuw><%bb> U: full-set S: full-set Exits: (8 + (16 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> + %q) LoopDispositions: { %bb: Computable }
34; CHECK-NEXT:    %t7 = add nsw i32 %i.01, 1
35; CHECK-NEXT:    --> {1,+,2}<nuw><nsw><%bb> U: [1,2147483646) S: [1,2147483646) Exits: (1 + (2 * ((-1 + (2 * (%no /u 2))<nuw>) /u 2))<nuw>)<nuw><nsw> LoopDispositions: { %bb: Computable }
36; CHECK-NEXT:    %t8 = sext i32 %t7 to i64
37; CHECK-NEXT:    --> {1,+,2}<nuw><nsw><%bb> U: [1,2147483646) S: [1,2147483646) Exits: (1 + (2 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw>)<nuw><nsw> LoopDispositions: { %bb: Computable }
38; CHECK-NEXT:    %t9 = getelementptr inbounds double, ptr %q, i64 %t8
39; CHECK-NEXT:    --> {(8 + %q),+,16}<nuw><%bb> U: full-set S: full-set Exits: (8 + (16 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> + %q) LoopDispositions: { %bb: Computable }
40; CHECK-NEXT:    %14 = sext i32 %i.01 to i64
41; CHECK-NEXT:    --> {0,+,2}<nuw><nsw><%bb> U: [0,2147483645) S: [0,2147483645) Exits: (2 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> LoopDispositions: { %bb: Computable }
42; CHECK-NEXT:    %15 = getelementptr inbounds double, ptr %d, i64 %14
43; CHECK-NEXT:    --> {%d,+,16}<nuw><%bb> U: full-set S: full-set Exits: ((16 * ((1 + (zext i32 (-2 + (2 * (%no /u 2))<nuw>) to i64))<nuw><nsw> /u 2))<nuw><nsw> + %d) LoopDispositions: { %bb: Computable }
44; CHECK-NEXT:    %16 = add nsw i32 %i.01, 2
45; CHECK-NEXT:    --> {2,+,2}<nuw><nsw><%bb> U: [2,2147483647) S: [2,2147483647) Exits: (2 + (2 * ((-1 + (2 * (%no /u 2))<nuw>) /u 2))<nuw>) LoopDispositions: { %bb: Computable }
46; CHECK-NEXT:  Determining loop execution counts for: @foo
47; CHECK-NEXT:  Loop %bb: backedge-taken count is ((-1 + (2 * (%no /u 2))<nuw>) /u 2)
48; CHECK-NEXT:  Loop %bb: constant max backedge-taken count is i32 1073741822
49; CHECK-NEXT:  Loop %bb: symbolic max backedge-taken count is ((-1 + (2 * (%no /u 2))<nuw>) /u 2)
50; CHECK-NEXT:  Loop %bb: Trip multiple is 1
51;
52entry:
53  %n = and i32 %no, 4294967294
54  %0 = icmp sgt i32 %n, 0                         ; <i1> [#uses=1]
55  tail call void @llvm.assume(i1 %0)
56  br label %bb.nph
57
58bb.nph:                                           ; preds = %entry
59  br label %bb
60
61bb:                                               ; preds = %bb.nph, %bb1
62  %i.01 = phi i32 [ %16, %bb1 ], [ 0, %bb.nph ]   ; <i32> [#uses=5]
63
64  %1 = sext i32 %i.01 to i64                      ; <i64> [#uses=1]
65
66  %2 = getelementptr inbounds double, ptr %d, i64 %1  ; <ptr> [#uses=1]
67
68  %3 = load double, ptr %2, align 8                   ; <double> [#uses=1]
69  %4 = sext i32 %i.01 to i64                      ; <i64> [#uses=1]
70  %5 = getelementptr inbounds double, ptr %q, i64 %4  ; <ptr> [#uses=1]
71  %6 = load double, ptr %5, align 8                   ; <double> [#uses=1]
72  %7 = or disjoint i32 %i.01, 1                            ; <i32> [#uses=1]
73
74  %8 = sext i32 %7 to i64                         ; <i64> [#uses=1]
75
76  %9 = getelementptr inbounds double, ptr %q, i64 %8  ; <ptr> [#uses=1]
77
78; Artificially repeat the above three instructions, this time using
79; add nsw instead of or.
80  %t7 = add nsw i32 %i.01, 1                            ; <i32> [#uses=1]
81
82  %t8 = sext i32 %t7 to i64                         ; <i64> [#uses=1]
83
84  %t9 = getelementptr inbounds double, ptr %q, i64 %t8  ; <ptr> [#uses=1]
85
86  %10 = load double, ptr %9, align 8                  ; <double> [#uses=1]
87  %11 = fadd double %6, %10                       ; <double> [#uses=1]
88  %12 = fadd double %11, 3.200000e+00             ; <double> [#uses=1]
89  %13 = fmul double %3, %12                       ; <double> [#uses=1]
90  %14 = sext i32 %i.01 to i64                     ; <i64> [#uses=1]
91  %15 = getelementptr inbounds double, ptr %d, i64 %14 ; <ptr> [#uses=1]
92  store double %13, ptr %15, align 8
93  %16 = add nsw i32 %i.01, 2                      ; <i32> [#uses=2]
94  br label %bb1
95
96bb1:                                              ; preds = %bb
97  %17 = icmp slt i32 %16, %n                      ; <i1> [#uses=1]
98  br i1 %17, label %bb, label %bb1.return_crit_edge
99
100bb1.return_crit_edge:                             ; preds = %bb1
101  br label %return
102
103return:                                           ; preds = %bb1.return_crit_edge, %entry
104  ret void
105}
106
107declare void @llvm.assume(i1) nounwind
108