]> granicus.if.org Git - llvm/commitdiff
[Tests] Expand basic lftr coverage
authorPhilip Reames <listmail@philipreames.com>
Thu, 16 May 2019 23:41:28 +0000 (23:41 +0000)
committerPhilip Reames <listmail@philipreames.com>
Thu, 16 May 2019 23:41:28 +0000 (23:41 +0000)
Newly written tests to cover the simple cases.  We don't appear to have broad coverage of this transform anywhere.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360957 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/IndVarSimplify/lftr.ll

index 4b905c083ec94678c1ad44cb54e9535367d482bf..92aef1e8d786b425ddc3ed5a16fd5017c3848378 100644 (file)
@@ -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 {