| Teresa Johnson | 4ab0a9f | 2019-03-12 18:28:05 +0000 | [diff] [blame] | 1 | ; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-cast-depth=0 -analyze -scalar-evolution < %s | FileCheck %s |
| Max Kazantsev | dc80366 | 2017-06-15 11:48:21 +0000 | [diff] [blame] | 2 | |
| 3 | ; Check that depth set to 0 prevents getAddExpr and getMulExpr from making |
| 4 | ; transformations in SCEV. We expect the result to be very straightforward. |
| 5 | |
| 6 | define void @test_add(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { |
| 7 | ; CHECK-LABEL: @test_add |
| 8 | ; CHECK: %s2 = add i32 %s1, %p3 |
| 9 | ; CHECK-NEXT: --> (%a + %a + %b + %b + %c + %c + %d + %d + %e + %e + %f + %f) |
| 10 | %tmp0 = add i32 %a, %b |
| 11 | %tmp1 = add i32 %b, %c |
| 12 | %tmp2 = add i32 %c, %d |
| 13 | %tmp3 = add i32 %d, %e |
| 14 | %tmp4 = add i32 %e, %f |
| 15 | %tmp5 = add i32 %f, %a |
| 16 | |
| 17 | %p1 = add i32 %tmp0, %tmp3 |
| 18 | %p2 = add i32 %tmp1, %tmp4 |
| 19 | %p3 = add i32 %tmp2, %tmp5 |
| 20 | |
| 21 | %s1 = add i32 %p1, %p2 |
| 22 | %s2 = add i32 %s1, %p3 |
| 23 | ret void |
| 24 | } |
| 25 | |
| 26 | define void @test_mul(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { |
| 27 | ; CHECK-LABEL: @test_mul |
| 28 | ; CHECK: %s2 = mul i32 %s1, %p3 |
| 29 | ; CHECK-NEXT: --> (2 * 3 * 4 * 5 * 6 * 7 * %a * %b * %c * %d * %e * %f) |
| 30 | %tmp0 = mul i32 %a, 2 |
| 31 | %tmp1 = mul i32 %b, 3 |
| 32 | %tmp2 = mul i32 %c, 4 |
| 33 | %tmp3 = mul i32 %d, 5 |
| 34 | %tmp4 = mul i32 %e, 6 |
| 35 | %tmp5 = mul i32 %f, 7 |
| 36 | |
| 37 | %p1 = mul i32 %tmp0, %tmp3 |
| 38 | %p2 = mul i32 %tmp1, %tmp4 |
| 39 | %p3 = mul i32 %tmp2, %tmp5 |
| 40 | |
| 41 | %s1 = mul i32 %p1, %p2 |
| 42 | %s2 = mul i32 %s1, %p3 |
| 43 | ret void |
| 44 | } |
| Max Kazantsev | 8d0322e | 2017-06-30 05:04:09 +0000 | [diff] [blame] | 45 | |
| 46 | define void @test_sext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { |
| 47 | ; CHECK-LABEL: @test_sext |
| 48 | ; CHECK: %se2 = sext i64 %iv2.inc to i128 |
| Tim Northover | 58e8c79 | 2019-09-30 07:46:52 +0000 | [diff] [blame] | 49 | ; CHECK-NEXT: --> {(1 + (sext i64 {(sext i32 (1 + %a) to i64),+,1}<nsw><%loop> to i128))<nsw>,+,1}<nsw><%loop2> |
| Max Kazantsev | 8d0322e | 2017-06-30 05:04:09 +0000 | [diff] [blame] | 50 | entry: |
| 51 | br label %loop |
| 52 | |
| 53 | loop: |
| 54 | %iv = phi i32 [ %a, %entry ], [ %iv.inc, %loop ] |
| 55 | %iv.inc = add nsw i32 %iv, 1 |
| 56 | %cond = icmp sle i32 %iv.inc, 50 |
| 57 | br i1 %cond, label %loop, label %between |
| 58 | |
| 59 | between: |
| 60 | %se = sext i32 %iv.inc to i64 |
| 61 | br label %loop2 |
| 62 | |
| 63 | loop2: |
| 64 | %iv2 = phi i64 [ %se, %between ], [ %iv2.inc, %loop2 ] |
| 65 | %iv2.inc = add nsw i64 %iv2, 1 |
| 66 | %cond2 = icmp sle i64 %iv2.inc, 50 |
| 67 | br i1 %cond2, label %loop2, label %exit |
| 68 | |
| 69 | exit: |
| 70 | %se2 = sext i64 %iv2.inc to i128 |
| 71 | ret void |
| 72 | } |
| 73 | |
| 74 | define void @test_zext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { |
| 75 | ; CHECK-LABEL: @test_zext |
| 76 | ; CHECK: %ze2 = zext i64 %iv2.inc to i128 |
| 77 | ; CHECK-NEXT: --> {(1 + (zext i64 {7,+,1}<nuw><nsw><%loop> to i128))<nuw><nsw>,+,1}<nuw><%loop2> |
| 78 | entry: |
| 79 | br label %loop |
| 80 | |
| 81 | loop: |
| 82 | %iv = phi i32 [ 6, %entry ], [ %iv.inc, %loop ] |
| 83 | %iv.inc = add nsw i32 %iv, 1 |
| 84 | %cond = icmp sle i32 %iv.inc, 50 |
| 85 | br i1 %cond, label %loop, label %between |
| 86 | |
| 87 | between: |
| 88 | %ze = zext i32 %iv.inc to i64 |
| 89 | br label %loop2 |
| 90 | |
| 91 | loop2: |
| 92 | %iv2 = phi i64 [ %ze, %between ], [ %iv2.inc, %loop2 ] |
| 93 | %iv2.inc = add nuw i64 %iv2, 1 |
| 94 | %cond2 = icmp sle i64 %iv2.inc, 50 |
| 95 | br i1 %cond2, label %loop2, label %exit |
| 96 | |
| 97 | exit: |
| 98 | %ze2 = zext i64 %iv2.inc to i128 |
| 99 | ret void |
| 100 | } |
| Teresa Johnson | 4ab0a9f | 2019-03-12 18:28:05 +0000 | [diff] [blame] | 101 | |
| 102 | define void @test_trunc(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { |
| 103 | ; CHECK-LABEL: @test_trunc |
| 104 | ; CHECK: %trunc2 = trunc i64 %iv2.inc to i32 |
| 105 | ; CHECK-NEXT: --> {(trunc i64 (1 + {7,+,1}<%loop>) to i32),+,1}<%loop2> |
| 106 | entry: |
| 107 | br label %loop |
| 108 | |
| 109 | loop: |
| 110 | %iv = phi i128 [ 6, %entry ], [ %iv.inc, %loop ] |
| 111 | %iv.inc = add nsw i128 %iv, 1 |
| 112 | %cond = icmp sle i128 %iv.inc, 50 |
| 113 | br i1 %cond, label %loop, label %between |
| 114 | |
| 115 | between: |
| 116 | %trunc = trunc i128 %iv.inc to i64 |
| 117 | br label %loop2 |
| 118 | |
| 119 | loop2: |
| 120 | %iv2 = phi i64 [ %trunc, %between ], [ %iv2.inc, %loop2 ] |
| 121 | %iv2.inc = add nuw i64 %iv2, 1 |
| 122 | %cond2 = icmp sle i64 %iv2.inc, 50 |
| 123 | br i1 %cond2, label %loop2, label %exit |
| 124 | |
| 125 | exit: |
| 126 | %trunc2 = trunc i64 %iv2.inc to i32 |
| 127 | ret void |
| 128 | } |
| Denis Antrushin | 5451289 | 2020-05-13 20:55:07 +0300 | [diff] [blame^] | 129 | |
| 130 | ; Check that all constant SCEVs are folded regardless depth limit. |
| 131 | define void @test_mul_const(i32 %a) { |
| 132 | ; CHECK-LABEL: @test_mul_const |
| 133 | ; CHECK: %test3 = mul i32 %test2, 3 |
| 134 | ; CHECK-NEXT: --> (9 + (3 * (3 * %a))) |
| 135 | ; CHECK: %test4 = mul i32 3, 3 |
| 136 | ; CHECK-NEXT: --> 9 U: [9,10) S: [9,10) |
| 137 | %test = mul i32 3, %a |
| 138 | %test2 = add i32 3, %test |
| 139 | %test3 = mul i32 %test2, 3 |
| 140 | %test4 = mul i32 3, 3 |
| 141 | ret void |
| 142 | } |