diff options
author | Philip Reames <listmail@philipreames.com> | 2019-05-16 23:41:28 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-05-16 23:41:28 +0000 |
commit | 087a30d52717414f96e2610dfaa50a2d6895f410 (patch) | |
tree | e32e7d4049e38193cc7bcbe52344bca23fc2d2e0 /llvm/test/Transforms/IndVarSimplify | |
parent | 2b9a3ea13f4eeb97dcad24396ded474e2e06b14a (diff) | |
download | bcm5719-llvm-087a30d52717414f96e2610dfaa50a2d6895f410.tar.gz bcm5719-llvm-087a30d52717414f96e2610dfaa50a2d6895f410.zip |
[Tests] Expand basic lftr coverage
Newly written tests to cover the simple cases. We don't appear to have broad coverage of this transform anywhere.
llvm-svn: 360957
Diffstat (limited to 'llvm/test/Transforms/IndVarSimplify')
-rw-r--r-- | llvm/test/Transforms/IndVarSimplify/lftr.ll | 126 |
1 files changed, 121 insertions, 5 deletions
diff --git a/llvm/test/Transforms/IndVarSimplify/lftr.ll b/llvm/test/Transforms/IndVarSimplify/lftr.ll index 4b905c083ec..92aef1e8d78 100644 --- a/llvm/test/Transforms/IndVarSimplify/lftr.ll +++ b/llvm/test/Transforms/IndVarSimplify/lftr.ll @@ -1,16 +1,73 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -indvars -dce -S | FileCheck %s -; LFTR should eliminate the need for the computation of i*i completely. It -; is only used to compute the exit value. - ; Provide legal integer types. target datalayout = "n8:16:32:64" @A = external global i32 -define i32 @quadratic_setlt() { -; CHECK-LABEL: @quadratic_setlt( +;; Convert a pre-increment check on the latch into a post increment check +define i32 @pre_to_post_add() { +; CHECK-LABEL: @pre_to_post_add( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: store i32 [[I]], i32* @A +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], 1001 +; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[LOOPEXIT:%.*]] +; CHECK: loopexit: +; CHECK-NEXT: ret i32 1000 +; +entry: + br label %loop + +loop: + %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] + %i.next = add i32 %i, 1 + store i32 %i, i32* @A + %c = icmp slt i32 %i, 1000 + br i1 %c, label %loop, label %loopexit + +loopexit: + ret i32 %i +} + +; TODO: we should be able to convert the subtract into a post-decrement check +define i32 @pre_to_post_sub() { +; CHECK-LABEL: @pre_to_post_sub( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 1000, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[I_NEXT]] = sub nsw i32 [[I]], 1 +; CHECK-NEXT: store i32 [[I]], i32* @A +; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[I]], 0 +; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[LOOPEXIT:%.*]] +; CHECK: loopexit: +; CHECK-NEXT: ret i32 0 +; +entry: + br label %loop + +loop: + %i = phi i32 [ 1000, %entry ], [ %i.next, %loop ] + %i.next = sub i32 %i, 1 + store i32 %i, i32* @A + %c = icmp sgt i32 %i, 0 + br i1 %c, label %loop, label %loopexit + +loopexit: + ret i32 %i +} + + + +; LFTR should eliminate the need for the computation of i*i completely. It +; is only used to compute the exit value. +define i32 @quadratic_slt() { +; CHECK-LABEL: @quadratic_slt( ; CHECK-NEXT: entry: ; CHECK-NEXT: br label [[LOOP:%.*]] ; CHECK: loop: @@ -38,6 +95,65 @@ loopexit: } +; Same as previous but with sle test +define i32 @quadratic_sle() { +; CHECK-LABEL: @quadratic_sle( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 7, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: store i32 [[I]], i32* @A +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], 33 +; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[LOOPEXIT:%.*]] +; CHECK: loopexit: +; CHECK-NEXT: ret i32 32 +; +entry: + br label %loop + +loop: + %i = phi i32 [ 7, %entry ], [ %i.next, %loop ] + %i.next = add i32 %i, 1 + store i32 %i, i32* @A + %i2 = mul i32 %i, %i + %c = icmp sle i32 %i2, 1000 + br i1 %c, label %loop, label %loopexit + +loopexit: + ret i32 %i +} + +; Same as previous but with ule test +define i32 @quadratic_ule() { +; CHECK-LABEL: @quadratic_ule( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 7, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: store i32 [[I]], i32* @A +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], 33 +; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[LOOPEXIT:%.*]] +; CHECK: loopexit: +; CHECK-NEXT: ret i32 32 +; +entry: + br label %loop + +loop: + %i = phi i32 [ 7, %entry ], [ %i.next, %loop ] + %i.next = add i32 %i, 1 + store i32 %i, i32* @A + %i2 = mul i32 %i, %i + %c = icmp ule i32 %i2, 1000 + br i1 %c, label %loop, label %loopexit + +loopexit: + ret i32 %i +} + + @data = common global [240 x i8] zeroinitializer, align 16 define void @test_zext(i8* %a) #0 { |