[llvm] r360957 - [Tests] Expand basic lftr coverage

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 16:41:29 PDT 2019


Author: reames
Date: Thu May 16 16:41:28 2019
New Revision: 360957

URL: http://llvm.org/viewvc/llvm-project?rev=360957&view=rev
Log:
[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.


Modified:
    llvm/trunk/test/Transforms/IndVarSimplify/lftr.ll

Modified: llvm/trunk/test/Transforms/IndVarSimplify/lftr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/lftr.ll?rev=360957&r1=360956&r2=360957&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/lftr.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/lftr.ll Thu May 16 16:41:28 2019
@@ -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:
@@ -34,6 +91,65 @@ loop:
   br i1 %c, label %loop, label %loopexit
 
 loopexit:
+  ret i32 %i
+}
+
+
+; 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
 }
 




More information about the llvm-commits mailing list