1 ; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-cast-depth=0 -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
2 ; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-cast-depth=0 -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
4 ; Check that depth set to 0 prevents getAddExpr and getMulExpr from making
5 ; transformations in SCEV. We expect the result to be very straightforward.
7 define void @test_add(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {
8 ; CHECK-LABEL: @test_add
9 ; CHECK: %s2 = add i32 %s1, %p3
10 ; CHECK-NEXT: --> (%a + %a + %b + %b + %c + %c + %d + %d + %e + %e + %f + %f)
11 %tmp0 = add i32 %a, %b
12 %tmp1 = add i32 %b, %c
13 %tmp2 = add i32 %c, %d
14 %tmp3 = add i32 %d, %e
15 %tmp4 = add i32 %e, %f
16 %tmp5 = add i32 %f, %a
18 %p1 = add i32 %tmp0, %tmp3
19 %p2 = add i32 %tmp1, %tmp4
20 %p3 = add i32 %tmp2, %tmp5
22 %s1 = add i32 %p1, %p2
23 %s2 = add i32 %s1, %p3
27 ; Constant factors still get folded together.
28 define void @test_mul_consts(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {
29 ; CHECK-LABEL: @test_mul_consts
30 ; CHECK: %s2 = mul i32 %s1, %p3
31 ; CHECK-NEXT: --> (5040 * %a * %b * %c * %d * %e * %f)
39 %p1 = mul i32 %tmp0, %tmp3
40 %p2 = mul i32 %tmp1, %tmp4
41 %p3 = mul i32 %tmp2, %tmp5
43 %s1 = mul i32 %p1, %p2
44 %s2 = mul i32 %s1, %p3
48 ; The outer *5 gets distributed because it is at depth=0, but the resulting
49 ; nested multiply doesn't get flattened, because it is at depth=1.
50 define void @test_mul(i32 %a, i32 %b) {
51 ; CHECK-LABEL: @test_mul
52 ; CHECK: %tmp2 = mul i32 %tmp1, 5
53 ; CHECK-NEXT: --> (20 + (5 * (3 * %a)))
55 %tmp1 = add i32 %tmp0, 4
56 %tmp2 = mul i32 %tmp1, 5
60 define void @test_sext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {
61 ; CHECK-LABEL: @test_sext
62 ; CHECK: %se2 = sext i64 %iv2.inc to i128
63 ; CHECK-NEXT: --> {(1 + (sext i64 {(sext i32 (1 + %a) to i64),+,1}<nsw><%loop> to i128))<nsw>,+,1}<nsw><%loop2>
68 %iv = phi i32 [ %a, %entry ], [ %iv.inc, %loop ]
69 %iv.inc = add nsw i32 %iv, 1
70 %cond = icmp sle i32 %iv.inc, 50
71 br i1 %cond, label %loop, label %between
74 %se = sext i32 %iv.inc to i64
78 %iv2 = phi i64 [ %se, %between ], [ %iv2.inc, %loop2 ]
79 %iv2.inc = add nsw i64 %iv2, 1
80 %cond2 = icmp sle i64 %iv2.inc, 50
81 br i1 %cond2, label %loop2, label %exit
84 %se2 = sext i64 %iv2.inc to i128
88 define void @test_zext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {
89 ; CHECK-LABEL: @test_zext
90 ; CHECK: %ze2 = zext i64 %iv2.inc to i128
91 ; CHECK-NEXT: --> {(1 + (zext i64 {7,+,1}<nuw><nsw><%loop> to i128))<nuw><nsw>,+,1}<nuw><%loop2>
96 %iv = phi i32 [ 6, %entry ], [ %iv.inc, %loop ]
97 %iv.inc = add nsw i32 %iv, 1
98 %cond = icmp sle i32 %iv.inc, 50
99 br i1 %cond, label %loop, label %between
102 %ze = zext i32 %iv.inc to i64
106 %iv2 = phi i64 [ %ze, %between ], [ %iv2.inc, %loop2 ]
107 %iv2.inc = add nuw i64 %iv2, 1
108 %cond2 = icmp sle i64 %iv2.inc, 50
109 br i1 %cond2, label %loop2, label %exit
112 %ze2 = zext i64 %iv2.inc to i128
116 define void @test_trunc(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {
117 ; CHECK-LABEL: @test_trunc
118 ; CHECK: %trunc2 = trunc i64 %iv2.inc to i32
119 ; CHECK-NEXT: --> {(trunc i64 (1 + {7,+,1}<%loop>) to i32),+,1}<%loop2>
124 %iv = phi i128 [ 6, %entry ], [ %iv.inc, %loop ]
125 %iv.inc = add nsw i128 %iv, 1
126 %cond = icmp sle i128 %iv.inc, 50
127 br i1 %cond, label %loop, label %between
130 %trunc = trunc i128 %iv.inc to i64
134 %iv2 = phi i64 [ %trunc, %between ], [ %iv2.inc, %loop2 ]
135 %iv2.inc = add nuw i64 %iv2, 1
136 %cond2 = icmp sle i64 %iv2.inc, 50
137 br i1 %cond2, label %loop2, label %exit
140 %trunc2 = trunc i64 %iv2.inc to i32
144 ; Check that all constant SCEVs are folded regardless depth limit.
145 define void @test_mul_const(i32 %a) {
146 ; CHECK-LABEL: @test_mul_const
147 ; CHECK: %test3 = mul i32 %test2, 3
148 ; CHECK-NEXT: --> (9 + (3 * (3 * %a)))
149 ; CHECK: %test4 = mul i32 3, 3
150 ; CHECK-NEXT: --> 9 U: [9,10) S: [9,10)
151 %test = mul i32 3, %a
152 %test2 = add i32 3, %test
153 %test3 = mul i32 %test2, 3
154 %test4 = mul i32 3, 3