1 ; RUN: opt < %s -S -analyze -enable-new-pm=0 -scalar-evolution | FileCheck %s
2 ; RUN: opt < %s -S -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
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).
9 target 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"
11 define void @foo(i32 %no, double* nocapture %d, double* nocapture %q) nounwind {
13 %n = and i32 %no, 4294967294
14 %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
15 tail call void @llvm.assume(i1 %0)
18 bb.nph: ; preds = %entry
21 bb: ; preds = %bb.nph, %bb1
22 %i.01 = phi i32 [ %16, %bb1 ], [ 0, %bb.nph ] ; <i32> [#uses=5]
24 ; CHECK: %1 = sext i32 %i.01 to i64
25 ; CHECK: --> {0,+,2}<nuw><nsw><%bb>
26 %1 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
28 ; CHECK: %2 = getelementptr inbounds double, double* %d, i64 %1
29 ; CHECK: --> {%d,+,16}<nuw><%bb>
30 %2 = getelementptr inbounds double, double* %d, i64 %1 ; <double*> [#uses=1]
32 %3 = load double, double* %2, align 8 ; <double> [#uses=1]
33 %4 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
34 %5 = getelementptr inbounds double, double* %q, i64 %4 ; <double*> [#uses=1]
35 %6 = load double, double* %5, align 8 ; <double> [#uses=1]
36 %7 = or i32 %i.01, 1 ; <i32> [#uses=1]
38 ; CHECK: %8 = sext i32 %7 to i64
39 ; CHECK: --> {1,+,2}<nuw><nsw><%bb>
40 %8 = sext i32 %7 to i64 ; <i64> [#uses=1]
42 ; CHECK: %9 = getelementptr inbounds double, double* %q, i64 %8
43 ; CHECK: {(8 + %q)<nuw>,+,16}<nuw><%bb>
44 %9 = getelementptr inbounds double, double* %q, i64 %8 ; <double*> [#uses=1]
46 ; Artificially repeat the above three instructions, this time using
47 ; add nsw instead of or.
48 %t7 = add nsw i32 %i.01, 1 ; <i32> [#uses=1]
50 ; CHECK: %t8 = sext i32 %t7 to i64
51 ; CHECK: --> {1,+,2}<nuw><nsw><%bb>
52 %t8 = sext i32 %t7 to i64 ; <i64> [#uses=1]
54 ; CHECK: %t9 = getelementptr inbounds double, double* %q, i64 %t8
55 ; CHECK: {(8 + %q)<nuw>,+,16}<nuw><%bb>
56 %t9 = getelementptr inbounds double, double* %q, i64 %t8 ; <double*> [#uses=1]
58 %10 = load double, double* %9, align 8 ; <double> [#uses=1]
59 %11 = fadd double %6, %10 ; <double> [#uses=1]
60 %12 = fadd double %11, 3.200000e+00 ; <double> [#uses=1]
61 %13 = fmul double %3, %12 ; <double> [#uses=1]
62 %14 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
63 %15 = getelementptr inbounds double, double* %d, i64 %14 ; <double*> [#uses=1]
64 store double %13, double* %15, align 8
65 %16 = add nsw i32 %i.01, 2 ; <i32> [#uses=2]
69 %17 = icmp slt i32 %16, %n ; <i1> [#uses=1]
70 br i1 %17, label %bb, label %bb1.return_crit_edge
72 bb1.return_crit_edge: ; preds = %bb1
75 return: ; preds = %bb1.return_crit_edge, %entry
79 declare void @llvm.assume(i1) nounwind
81 ; Note: Without the preheader assume, there is an 'smax' in the
82 ; backedge-taken count expression:
83 ; CHECK: Loop %bb: backedge-taken count is ((-1 + (2 * (%no /u 2))<nuw>) /u 2)
84 ; CHECK: Loop %bb: max backedge-taken count is 1073741822