diff options
| author | Justin Lebar <jlebar@google.com> | 2018-06-14 17:13:35 +0000 |
|---|---|---|
| committer | Justin Lebar <jlebar@google.com> | 2018-06-14 17:13:35 +0000 |
| commit | b326904dba986560d5d27da8bd67b963a14079b3 (patch) | |
| tree | 9cafa8bf4f971a89683f84890bc1882be66679cb /llvm/test | |
| parent | 62a0747926cc4087bbfd9bf48ca0a9a19d1cdb7b (diff) | |
| download | bcm5719-llvm-b326904dba986560d5d27da8bd67b963a14079b3.tar.gz bcm5719-llvm-b326904dba986560d5d27da8bd67b963a14079b3.zip | |
[SCEV] Simplify trunc-of-add/mul to add/mul-of-trunc under more circumstances.
Summary:
Previously we would do this simplification only if it did not introduce
any new truncs (excepting new truncs which replace other cast ops).
This change weakens this condition: If the number of truncs stays the
same, but we're able to transform trunc(X + Y) to X + trunc(Y), that's
still simpler, and it may open up additional transformations.
While we're here, also clean up some duplicated code.
Reviewers: sanjoy
Subscribers: hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D48160
llvm-svn: 334736
Diffstat (limited to 'llvm/test')
5 files changed, 34 insertions, 8 deletions
diff --git a/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll b/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll index 42d2a3722b1..17e7a778abb 100644 --- a/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll +++ b/llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll @@ -277,9 +277,10 @@ define void @test_04() { ; CHECK: %tmp11 = add i64 %tmp10, undef ; CHECK-NEXT: --> ((sext i8 %tmp8 to i64) + {(-2 + undef),+,-1}<nw><%loop2>) ; CHECK: %tmp13 = trunc i64 %tmp11 to i32 -; CHECK-NEXT: --> ((sext i8 %tmp8 to i32) + {(trunc i64 (-2 + undef) to i32),+,-1}<%loop2>) +; CHECK-NEXT: --> ((sext i8 %tmp8 to i32) + {(-2 + (trunc i64 undef to i32)),+,-1}<%loop2>) ; CHECK: %tmp14 = sub i32 %tmp13, %tmp2 -; CHECK-NEXT: --> ((sext i8 %tmp8 to i32) + {{{{}}(-2 + (trunc i64 (-2 + undef) to i32)),+,-1}<%loop1>,+,-1}<%loop2>) +; `{{[{][{]}}` is the ugliness needed to match `{{` +; CHECK-NEXT: --> ((sext i8 %tmp8 to i32) + {{[{][{]}}(-4 + (trunc i64 undef to i32)),+,-1}<%loop1>,+,-1}<%loop2>) ; CHECK: %tmp15 = add nuw nsw i64 %tmp7, 1 ; CHECK-NEXT: --> {3,+,1}<nuw><nsw><%loop2> @@ -462,9 +463,9 @@ define void @test_08() { ; CHECK: %tmp11 = add i64 %iv.2.2, %iv.2.1 ; CHECK-NEXT: --> ({0,+,-1}<nsw><%loop_2> + %iv.2.1) ; CHECK: %tmp12 = trunc i64 %tmp11 to i32 -; CHECK-NEXT: --> (trunc i64 ({0,+,-1}<nsw><%loop_2> + %iv.2.1) to i32) +; CHECK-NEXT: --> ((trunc i64 %iv.2.1 to i32) + {0,+,-1}<%loop_2>) ; CHECK: %tmp14 = mul i32 %tmp12, %tmp7 -; CHECK-NEXT: --> ((trunc i64 ({0,+,-1}<nsw><%loop_2> + %iv.2.1) to i32) * {-1,+,-1}<%loop_1>) +; CHECK-NEXT: --> (((trunc i64 %iv.2.1 to i32) + {0,+,-1}<%loop_2>) * {-1,+,-1}<%loop_1>) ; CHECK: %tmp16 = mul i64 %iv.2.1, %iv.1.1 ; CHECK-NEXT: --> ({2,+,1}<nuw><nsw><%loop_1> * %iv.2.1) diff --git a/llvm/test/Analysis/ScalarEvolution/max-trip-count-address-space.ll b/llvm/test/Analysis/ScalarEvolution/max-trip-count-address-space.ll index 8d6cb2fbf63..1c72440a749 100644 --- a/llvm/test/Analysis/ScalarEvolution/max-trip-count-address-space.ll +++ b/llvm/test/Analysis/ScalarEvolution/max-trip-count-address-space.ll @@ -4,7 +4,7 @@ target datalayout = "e-p:32:32:32-p1:16:16:16-p2:8:8:8-p4:64:64:64-n16:32:64" -; CHECK: {%d,+,4}<%bb>{{ U: [^ ]+ S: [^ ]+}}{{ *}}Exits: ((4 * (trunc i32 (-1 + %n) to i16)) + %d) +; CHECK: {%d,+,4}<%bb>{{ U: [^ ]+ S: [^ ]+}}{{ *}} Exits: (-4 + (4 * (trunc i32 %n to i16)) + %d) define void @foo(i32 addrspace(1)* nocapture %d, i32 %n) nounwind { diff --git a/llvm/test/Analysis/ScalarEvolution/sext-inreg.ll b/llvm/test/Analysis/ScalarEvolution/sext-inreg.ll index 39b3fa50227..cc738a17bc4 100644 --- a/llvm/test/Analysis/ScalarEvolution/sext-inreg.ll +++ b/llvm/test/Analysis/ScalarEvolution/sext-inreg.ll @@ -15,10 +15,10 @@ bb: %t2 = ashr i64 %t1, 7 ; CHECK: %t2 = ashr i64 %t1, 7 ; CHECK-NEXT: sext i57 {0,+,199}<%bb> to i64 -; CHECK-SAME: Exits: (sext i57 (199 * (trunc i64 (-1 + (2780916192016515319 * %n)) to i57)) to i64) +; CHECK-SAME: Exits: (sext i57 (-199 + (trunc i64 %n to i57)) to i64) ; CHECK: %s2 = ashr i64 %s1, 5 ; CHECK-NEXT: sext i59 {0,+,199}<%bb> to i64 -; CHECK-SAME: Exits: (sext i59 (199 * (trunc i64 (-1 + (2780916192016515319 * %n)) to i59)) to i64) +; CHECK-SAME: Exits: (sext i59 (-199 + (trunc i64 %n to i59)) to i64) %s1 = shl i64 %i.01, 5 %s2 = ashr i64 %s1, 5 %t3 = getelementptr i64, i64* %x, i64 %i.01 diff --git a/llvm/test/Analysis/ScalarEvolution/strip-injective-zext.ll b/llvm/test/Analysis/ScalarEvolution/strip-injective-zext.ll index 661b48f6fe5..b618b71a358 100644 --- a/llvm/test/Analysis/ScalarEvolution/strip-injective-zext.ll +++ b/llvm/test/Analysis/ScalarEvolution/strip-injective-zext.ll @@ -9,7 +9,7 @@ ; Check that the backedge taken count was actually computed: ; CHECK: Determining loop execution counts for: @f0 -; CHECK-NEXT: Loop %b2: backedge-taken count is (-1 * (trunc i32 (1 + %a1) to i2)) +; CHECK-NEXT: Loop %b2: backedge-taken count is (-1 + (-1 * (trunc i32 %a1 to i2))) target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" diff --git a/llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll b/llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll new file mode 100644 index 00000000000..cf37371939d --- /dev/null +++ b/llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll @@ -0,0 +1,25 @@ +; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s + +; Check that we convert +; trunc(C * a) -> trunc(C) * trunc(a) +; if C is a constant. +; CHECK-LABEL: @trunc_of_mul +define i8 @trunc_of_mul(i32 %a) { + %b = mul i32 %a, 100 + ; CHECK: %c + ; CHECK-NEXT: --> (100 * (trunc i32 %a to i8)) + %c = trunc i32 %b to i8 + ret i8 %c +} + +; Check that we convert +; trunc(C + a) -> trunc(C) + trunc(a) +; if C is a constant. +; CHECK-LABEL: @trunc_of_add +define i8 @trunc_of_add(i32 %a) { + %b = add i32 %a, 100 + ; CHECK: %c + ; CHECK-NEXT: --> (100 + (trunc i32 %a to i8)) + %c = trunc i32 %b to i8 + ret i8 %c +} |

