[llvm] 0304fbc - [SCEV] Improve loop guard tests (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 27 13:35:05 PDT 2021


Author: Nikita Popov
Date: 2021-04-27T22:34:56+02:00
New Revision: 0304fbcd6cc19f855ee266577ce04f49360013a8

URL: https://github.com/llvm/llvm-project/commit/0304fbcd6cc19f855ee266577ce04f49360013a8
DIFF: https://github.com/llvm/llvm-project/commit/0304fbcd6cc19f855ee266577ce04f49360013a8.diff

LOG: [SCEV] Improve loop guard tests (NFC)

Invert the branch order to make the predicate more obvious.
Add tests with two predicates, to show that rewrites are
combined.

Added: 
    

Modified: 
    llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
index 7419fa9fd3006..ab64b154c58ba 100644
--- a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
+++ b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
@@ -633,8 +633,8 @@ define void @test_guard_uge(i32 %blockSize) {
 ; CHECK:       Loop %while.body: Trip multiple is 1
 ;
   %shr = lshr i32 %blockSize, 2
-  %guard = icmp ult i32 %blockSize, 4
-  br i1 %guard, label %while.end, label %while.body.preheader
+  %guard = icmp uge i32 %blockSize, 4
+  br i1 %guard, label %while.body.preheader, label %while.end
 
 while.body.preheader:
   br label %while.body
@@ -669,8 +669,88 @@ define void @test_guard_ugt(i32 %blockSize) {
 ; CHECK:       Loop %while.body: Trip multiple is 1
 ;
   %shr = lshr i32 %blockSize, 2
-  %guard = icmp ule i32 %blockSize, 3
-  br i1 %guard, label %while.end, label %while.body.preheader
+  %guard = icmp ugt i32 %blockSize, 3
+  br i1 %guard, label %while.body.preheader, label %while.end
+
+while.body.preheader:
+  br label %while.body
+
+while.body:
+  %iv = phi i32 [ %dec, %while.body ], [ %shr, %while.body.preheader ]
+  %dec = add i32 %iv, -1
+  %cmp.not = icmp eq i32 %dec, 0
+  br i1 %cmp.not, label %while.end.loopexit, label %while.body
+
+while.end.loopexit:
+  br label %while.end
+
+while.end:
+  ret void
+}
+
+define void @test_guard_uge_and_ule(i32 %blockSize) {
+; CHECK-LABEL: 'test_guard_uge_and_ule'
+; CHECK-NEXT:  Classifying expressions for: @test_guard_uge_and_ule
+; CHECK-NEXT:    %shr = lshr i32 %blockSize, 2
+; CHECK-NEXT:    --> (%blockSize /u 4) U: [0,1073741824) S: [0,1073741824)
+; CHECK-NEXT:    %iv = phi i32 [ %dec, %while.body ], [ %shr, %while.body.preheader ]
+; CHECK-NEXT:    --> {(%blockSize /u 4),+,-1}<%while.body> U: full-set S: full-set Exits: 1 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT:    %dec = add i32 %iv, -1
+; CHECK-NEXT:    --> {(-1 + (%blockSize /u 4))<nsw>,+,-1}<%while.body> U: full-set S: full-set Exits: 0 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test_guard_uge_and_ule
+; CHECK-NEXT:  Loop %while.body: backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
+; CHECK-NEXT:  Loop %while.body: max backedge-taken count is -1
+; CHECK-NEXT:  Loop %while.body: Predicated backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %while.body: Trip multiple is 1
+;
+  %shr = lshr i32 %blockSize, 2
+  %guard1 = icmp uge i32 %blockSize, 4
+  br i1 %guard1, label %while.guard, label %while.end
+
+while.guard:
+  %guard2 = icmp ule i32 %blockSize, 1024
+  br i1 %guard2, label %while.body.preheader, label %while.end
+
+while.body.preheader:
+  br label %while.body
+
+while.body:
+  %iv = phi i32 [ %dec, %while.body ], [ %shr, %while.body.preheader ]
+  %dec = add i32 %iv, -1
+  %cmp.not = icmp eq i32 %dec, 0
+  br i1 %cmp.not, label %while.end.loopexit, label %while.body
+
+while.end.loopexit:
+  br label %while.end
+
+while.end:
+  ret void
+}
+
+define void @test_guard_ugt_and_ult(i32 %blockSize) {
+; CHECK-LABEL: 'test_guard_ugt_and_ult'
+; CHECK-NEXT:  Classifying expressions for: @test_guard_ugt_and_ult
+; CHECK-NEXT:    %shr = lshr i32 %blockSize, 2
+; CHECK-NEXT:    --> (%blockSize /u 4) U: [0,1073741824) S: [0,1073741824)
+; CHECK-NEXT:    %iv = phi i32 [ %dec, %while.body ], [ %shr, %while.body.preheader ]
+; CHECK-NEXT:    --> {(%blockSize /u 4),+,-1}<%while.body> U: full-set S: full-set Exits: 1 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT:    %dec = add i32 %iv, -1
+; CHECK-NEXT:    --> {(-1 + (%blockSize /u 4))<nsw>,+,-1}<%while.body> U: full-set S: full-set Exits: 0 LoopDispositions: { %while.body: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test_guard_ugt_and_ult
+; CHECK-NEXT:  Loop %while.body: backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
+; CHECK-NEXT:  Loop %while.body: max backedge-taken count is -1
+; CHECK-NEXT:  Loop %while.body: Predicated backedge-taken count is (-1 + (%blockSize /u 4))<nsw>
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %while.body: Trip multiple is 1
+;
+  %shr = lshr i32 %blockSize, 2
+  %guard1 = icmp ugt i32 %blockSize, 3
+  br i1 %guard1, label %while.guard, label %while.end
+
+while.guard:
+  %guard2 = icmp ult i32 %blockSize, 1025
+  br i1 %guard2, label %while.body.preheader, label %while.end
 
 while.body.preheader:
   br label %while.body


        


More information about the llvm-commits mailing list