[llvm] 407ff50 - [SCEV] Add test for alloca ranges (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 23 05:08:46 PDT 2023


Author: Nikita Popov
Date: 2023-06-23T14:08:39+02:00
New Revision: 407ff50ecad8ecbbba66bcd3fca4519f9c60f9e5

URL: https://github.com/llvm/llvm-project/commit/407ff50ecad8ecbbba66bcd3fca4519f9c60f9e5
DIFF: https://github.com/llvm/llvm-project/commit/407ff50ecad8ecbbba66bcd3fca4519f9c60f9e5.diff

LOG: [SCEV] Add test for alloca ranges (NFC)

Added: 
    llvm/test/Analysis/ScalarEvolution/alloca.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/alloca.ll b/llvm/test/Analysis/ScalarEvolution/alloca.ll
new file mode 100644
index 0000000000000..16f2e879db248
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/alloca.ll
@@ -0,0 +1,68 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -passes='print<scalar-evolution>' -disable-output %s 2>&1 | FileCheck %s
+
+define i64 @alloca_non_null() {
+; CHECK-LABEL: 'alloca_non_null'
+; CHECK-NEXT:  Classifying expressions for: @alloca_non_null
+; CHECK-NEXT:    %alloca = alloca i32, align 4
+; CHECK-NEXT:    --> %alloca U: [0,-7) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT:    %int = ptrtoint ptr %alloca to i64
+; CHECK-NEXT:    --> (ptrtoint ptr %alloca to i64) U: [0,-7) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT:  Determining loop execution counts for: @alloca_non_null
+;
+  %alloca = alloca i32, align 4
+  %int = ptrtoint ptr %alloca to i64
+  ret i64 %int
+}
+
+define i64 @alloca_maybe_null() {
+; CHECK-LABEL: 'alloca_maybe_null'
+; CHECK-NEXT:  Classifying expressions for: @alloca_maybe_null
+; CHECK-NEXT:    %alloca = alloca i32, align 4, addrspace(1)
+; CHECK-NEXT:    --> %alloca U: [0,-7) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT:    %int = ptrtoint ptr addrspace(1) %alloca to i64
+; CHECK-NEXT:    --> (ptrtoint ptr addrspace(1) %alloca to i64) U: [0,-7) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT:  Determining loop execution counts for: @alloca_maybe_null
+;
+  %alloca = alloca i32, align 4, addrspace(1)
+  %int = ptrtoint ptr addrspace(1) %alloca to i64
+  ret i64 %int
+}
+
+define void @alloca_icmp_null_exit_count() {
+; CHECK-LABEL: 'alloca_icmp_null_exit_count'
+; CHECK-NEXT:  Classifying expressions for: @alloca_icmp_null_exit_count
+; CHECK-NEXT:    %alloca = alloca [3 x i32], align 4
+; CHECK-NEXT:    --> %alloca U: [0,-15) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT:    %alloca.end = getelementptr inbounds i32, ptr %alloca, i64 3
+; CHECK-NEXT:    --> (12 + %alloca)<nuw> U: [12,-3) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT:    %ptr = phi ptr [ %ptr.next, %loop ], [ %alloca, %entry ]
+; CHECK-NEXT:    --> {%alloca,+,4}<nuw><%loop> U: [0,-7) S: [-9223372036854775808,9223372036854775805) Exits: ((4 * (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4)))<nuw><nsw> + %alloca) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %ptr.next = getelementptr i32, ptr %ptr, i64 1
+; CHECK-NEXT:    --> {(4 + %alloca)<nuw>,+,4}<nuw><%loop> U: [4,-3) S: [-9223372036854775808,9223372036854775805) Exits: (4 + (4 * (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4)))<nuw><nsw> + %alloca) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %and = and i1 %cmp1, %cmp2
+; CHECK-NEXT:    --> (%cmp2 umin %cmp1) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT:  Determining loop execution counts for: @alloca_icmp_null_exit_count
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4))
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is 2
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4))
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4))
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  %alloca = alloca [3 x i32], align 4
+  %alloca.end = getelementptr inbounds i32, ptr %alloca, i64 3
+  br label %loop
+
+loop:
+  %ptr = phi ptr [ %ptr.next, %loop ], [ %alloca, %entry ]
+  %ptr.next = getelementptr i32, ptr %ptr, i64 1
+  %cmp1 = icmp ne ptr %ptr.next, %alloca.end
+  %cmp2 = icmp ne ptr %ptr.next, null
+  %and = and i1 %cmp1, %cmp2
+  br i1 %and, label %loop, label %exit
+
+exit:
+  ret void
+}


        


More information about the llvm-commits mailing list