156 lines · plain
1; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-cast-depth=0 -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s2 3; Check that depth set to 0 prevents getAddExpr and getMulExpr from making4; transformations in SCEV. We expect the result to be very straightforward.5 6define void @test_add(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {7; CHECK-LABEL: @test_add8; CHECK: %s2 = add i32 %s1, %p39; CHECK-NEXT: --> (%a + %a + %b + %b + %c + %c + %d + %d + %e + %e + %f + %f)10 %tmp0 = add i32 %a, %b11 %tmp1 = add i32 %b, %c12 %tmp2 = add i32 %c, %d13 %tmp3 = add i32 %d, %e14 %tmp4 = add i32 %e, %f15 %tmp5 = add i32 %f, %a16 17 %p1 = add i32 %tmp0, %tmp318 %p2 = add i32 %tmp1, %tmp419 %p3 = add i32 %tmp2, %tmp520 21 %s1 = add i32 %p1, %p222 %s2 = add i32 %s1, %p323 ret void24}25 26; Constant factors still get folded together.27define void @test_mul_consts(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {28; CHECK-LABEL: @test_mul_consts29; CHECK: %s2 = mul i32 %s1, %p330; CHECK-NEXT: --> (5040 * %a * %b * %c * %d * %e * %f)31 %tmp0 = mul i32 %a, 232 %tmp1 = mul i32 %b, 333 %tmp2 = mul i32 %c, 434 %tmp3 = mul i32 %d, 535 %tmp4 = mul i32 %e, 636 %tmp5 = mul i32 %f, 737 38 %p1 = mul i32 %tmp0, %tmp339 %p2 = mul i32 %tmp1, %tmp440 %p3 = mul i32 %tmp2, %tmp541 42 %s1 = mul i32 %p1, %p243 %s2 = mul i32 %s1, %p344 ret void45}46 47; The outer *5 gets distributed because it is at depth=0, but the resulting48; nested multiply doesn't get flattened, because it is at depth=1.49define void @test_mul(i32 %a, i32 %b) {50; CHECK-LABEL: @test_mul51; CHECK: %tmp2 = mul i32 %tmp1, 552; CHECK-NEXT: --> (20 + (5 * (3 * %a)))53 %tmp0 = mul i32 %a, 354 %tmp1 = add i32 %tmp0, 455 %tmp2 = mul i32 %tmp1, 556 ret void57}58 59define void @test_sext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {60; CHECK-LABEL: @test_sext61; CHECK: %se2 = sext i64 %iv2.inc to i12862; CHECK-NEXT: --> {(1 + (sext i64 {(sext i32 (1 + %a)<nsw> to i64),+,1}<nsw><%loop> to i128))<nsw>,+,1}<nsw><%loop2>63entry:64 br label %loop65 66loop:67 %iv = phi i32 [ %a, %entry ], [ %iv.inc, %loop ]68 %iv.inc = add nsw i32 %iv, 169 %cond = icmp sle i32 %iv.inc, 5070 br i1 %cond, label %loop, label %between71 72between:73 %se = sext i32 %iv.inc to i6474 br label %loop275 76loop2:77 %iv2 = phi i64 [ %se, %between ], [ %iv2.inc, %loop2 ]78 %iv2.inc = add nsw i64 %iv2, 179 %cond2 = icmp sle i64 %iv2.inc, 5080 br i1 %cond2, label %loop2, label %exit81 82exit:83 %se2 = sext i64 %iv2.inc to i12884 ret void85}86 87define void @test_zext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {88; CHECK-LABEL: @test_zext89; CHECK: %ze2 = zext i64 %iv2.inc to i12890; CHECK-NEXT: --> {(1 + (zext i64 {7,+,1}<nuw><nsw><%loop> to i128))<nuw><nsw>,+,1}<nuw><nsw><%loop2>91entry:92 br label %loop93 94loop:95 %iv = phi i32 [ 6, %entry ], [ %iv.inc, %loop ]96 %iv.inc = add nsw i32 %iv, 197 %cond = icmp sle i32 %iv.inc, 5098 br i1 %cond, label %loop, label %between99 100between:101 %ze = zext i32 %iv.inc to i64102 br label %loop2103 104loop2:105 %iv2 = phi i64 [ %ze, %between ], [ %iv2.inc, %loop2 ]106 %iv2.inc = add nuw i64 %iv2, 1107 %cond2 = icmp sle i64 %iv2.inc, 50108 br i1 %cond2, label %loop2, label %exit109 110exit:111 %ze2 = zext i64 %iv2.inc to i128112 ret void113}114 115define void @test_trunc(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {116; CHECK-LABEL: @test_trunc117; CHECK: %trunc2 = trunc i64 %iv2.inc to i32118; CHECK-NEXT: --> {(trunc i64 (1 + {7,+,1}<%loop>)<nuw><nsw> to i32),+,1}<%loop2> U: [8,53) S: [8,53) --> 52 U: [52,53) S: [52,53)119entry:120 br label %loop121 122loop:123 %iv = phi i128 [ 6, %entry ], [ %iv.inc, %loop ]124 %iv.inc = add nsw i128 %iv, 1125 %cond = icmp sle i128 %iv.inc, 50126 br i1 %cond, label %loop, label %between127 128between:129 %trunc = trunc i128 %iv.inc to i64130 br label %loop2131 132loop2:133 %iv2 = phi i64 [ %trunc, %between ], [ %iv2.inc, %loop2 ]134 %iv2.inc = add nuw i64 %iv2, 1135 %cond2 = icmp sle i64 %iv2.inc, 50136 br i1 %cond2, label %loop2, label %exit137 138exit:139 %trunc2 = trunc i64 %iv2.inc to i32140 ret void141}142 143; Check that all constant SCEVs are folded regardless depth limit.144define void @test_mul_const(i32 %a) {145; CHECK-LABEL: @test_mul_const146; CHECK: %test3 = mul i32 %test2, 3147; CHECK-NEXT: --> (9 + (3 * (3 * %a)))148; CHECK: %test4 = mul i32 3, 3149; CHECK-NEXT: --> 9 U: [9,10) S: [9,10)150 %test = mul i32 3, %a151 %test2 = add i32 3, %test152 %test3 = mul i32 %test2, 3153 %test4 = mul i32 3, 3154 ret void155}156