[llvm] 05a142c - [Test] Add tests showing flags improvement for SCEV sub expressions (NFC)

Dmitry Makogon via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 03:29:24 PDT 2023


Author: Dmitry Makogon
Date: 2023-04-14T17:28:35+07:00
New Revision: 05a142cc6fd16b88e567f845818d99b6f52fcfe8

URL: https://github.com/llvm/llvm-project/commit/05a142cc6fd16b88e567f845818d99b6f52fcfe8
DIFF: https://github.com/llvm/llvm-project/commit/05a142cc6fd16b88e567f845818d99b6f52fcfe8.diff

LOG: [Test] Add tests showing flags improvement for SCEV sub expressions (NFC)

Added: 
    llvm/test/Analysis/ScalarEvolution/addrec-sub-nsw.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/addrec-sub-nsw.ll b/llvm/test/Analysis/ScalarEvolution/addrec-sub-nsw.ll
new file mode 100644
index 0000000000000..f8c83fdef8242
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/addrec-sub-nsw.ll
@@ -0,0 +1,78 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
+
+define i32 @test_1_non_negative(i32 %n) {
+; CHECK-LABEL: 'test_1_non_negative'
+; CHECK-NEXT:  Classifying expressions for: @test_1_non_negative
+; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
+; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + (1 smax %n))<nsw> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %a = sub i32 %n, %i
+; CHECK-NEXT:    --> {%n,+,-1}<nw><%loop> U: full-set S: full-set Exits: (1 + (-1 * (1 smax %n))<nsw> + %n) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %i.next = add nuw nsw i32 %i, 1
+; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,-2147483648) S: [1,-2147483648) Exits: (1 smax %n) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test_1_non_negative
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-1 + (1 smax %n))<nsw>
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is 2147483646
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (-1 + (1 smax %n))<nsw>
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + (1 smax %n))<nsw>
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  %precond = icmp sge i32 %n, 0
+  br i1 %precond, label %loop, label %fail
+
+loop:
+  %i = phi i32 [0, %entry], [%i.next, %loop]                      ; 0...n-1
+  %a = sub i32 %n, %i                                             ; n...0
+  %i.next = add nuw nsw i32 %i, 1
+  %cond = icmp slt i32 %i.next, %n
+  br i1 %cond, label %loop, label %exit
+
+fail:
+  ret i32 -1
+
+exit:
+  ret i32 0
+}
+
+define i32 @test_2_non_positive(i32 %n) {
+; CHECK-LABEL: 'test_2_non_positive'
+; CHECK-NEXT:  Classifying expressions for: @test_2_non_positive
+; CHECK-NEXT:    %minus.n = mul i32 %n, -1
+; CHECK-NEXT:    --> (-1 * %n) U: full-set S: full-set
+; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
+; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + (1 smax %n))<nsw> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %minus.i = mul i32 %i, -1
+; CHECK-NEXT:    --> {0,+,-1}<nw><%loop> U: [-2147483646,1) S: [-2147483646,1) Exits: (1 + (-1 * (1 smax %n))<nsw>)<nsw> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %a = sub i32 %minus.n, %minus.i
+; CHECK-NEXT:    --> {(-1 * %n),+,1}<nsw><%loop> U: full-set S: full-set Exits: (-1 + (-1 * %n) + (1 smax %n)) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %i.next = add nuw nsw i32 %i, 1
+; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,-2147483648) S: [1,-2147483648) Exits: (1 smax %n) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test_2_non_positive
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-1 + (1 smax %n))<nsw>
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is 2147483646
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (-1 + (1 smax %n))<nsw>
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + (1 smax %n))<nsw>
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  %precond = icmp sge i32 %n, 0
+  %minus.n = mul i32 %n, -1
+  br i1 %precond, label %loop, label %fail
+
+loop:
+  %i = phi i32 [0, %entry], [%i.next, %loop]                      ; 0...n-1
+  %minus.i = mul i32 %i, -1                                       ; -(n-1)...0
+  %a = sub i32 %minus.n, %minus.i                                 ; -n...-1
+  %i.next = add nuw nsw i32 %i, 1
+  %cond = icmp slt i32 %i.next, %n
+  br i1 %cond, label %loop, label %exit
+
+fail:
+  ret i32 -1
+
+exit:
+  ret i32 0
+}


        


More information about the llvm-commits mailing list