[llvm] 3e50896 - [SCEV] Add additional tests for addrec nowrap flags (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 18 06:18:12 PDT 2023


Author: Nikita Popov
Date: 2023-04-18T15:18:04+02:00
New Revision: 3e508967fd1b1d77434bff3df7a7d7d98bf8e1e8

URL: https://github.com/llvm/llvm-project/commit/3e508967fd1b1d77434bff3df7a7d7d98bf8e1e8
DIFF: https://github.com/llvm/llvm-project/commit/3e508967fd1b1d77434bff3df7a7d7d98bf8e1e8.diff

LOG: [SCEV] Add additional tests for addrec nowrap flags (NFC)

Added: 
    

Modified: 
    llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll b/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll
index c52eb940f1490..9e21d635fec43 100644
--- a/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll
+++ b/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll
@@ -654,6 +654,127 @@ exit:
   ret void
 }
 
+; Variant where a separate IV is used for the load.
+define void @test-add-not-header6(ptr %input, i32 %offset, i32 %numIterations) {
+; CHECK-LABEL: 'test-add-not-header6'
+; CHECK-NEXT:  Classifying expressions for: @test-add-not-header6
+; CHECK-NEXT:    %i = phi i32 [ %nexti, %loop2 ], [ 0, %entry ]
+; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %i2 = phi i32 [ %nexti2, %loop2 ], [ %offset, %entry ]
+; CHECK-NEXT:    --> {%offset,+,1}<nsw><%loop> U: full-set S: full-set Exits: (-1 + %offset + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %nexti = add nsw i32 %i, 1
+; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,-2147483648) S: [1,-2147483648) Exits: %numIterations LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %nexti2 = add nsw i32 %i2, 1
+; CHECK-NEXT:    --> {(1 + %offset),+,1}<nw><%loop> U: full-set S: full-set Exits: (%offset + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %ptr = getelementptr inbounds float, ptr %input, i32 %nexti2
+; CHECK-NEXT:    --> ((4 * (sext i32 {(1 + %offset),+,1}<nw><%loop> to i64))<nsw> + %input) U: full-set S: full-set Exits: ((4 * (sext i32 (%offset + %numIterations) to i64))<nsw> + %input) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test-add-not-header6
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is -1
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  br label %loop
+loop:
+  %i = phi i32 [ %nexti, %loop2 ], [ 0, %entry ]
+  %i2 = phi i32 [ %nexti2, %loop2 ], [ %offset, %entry ]
+  br label %loop2
+loop2:
+  %nexti = add nsw i32 %i, 1
+  %nexti2 = add nsw i32 %i2, 1
+  %ptr = getelementptr inbounds float, ptr %input, i32 %nexti2
+  %f = load float, ptr %ptr, align 4
+  %exitcond = icmp eq i32 %nexti, %numIterations
+  br i1 %exitcond, label %exit, label %loop
+exit:
+  ret void
+}
+
+; Variant where the loop latch is not exiting.
+define void @test-add-not-header7(ptr %input, i32 %offset, i32 %numIterations) {
+; CHECK-LABEL: 'test-add-not-header7'
+; CHECK-NEXT:  Classifying expressions for: @test-add-not-header7
+; CHECK-NEXT:    %i = phi i32 [ %nexti, %loop.latch ], [ 0, %entry ]
+; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %i2 = phi i32 [ %nexti2, %loop.latch ], [ %offset, %entry ]
+; CHECK-NEXT:    --> {%offset,+,1}<nsw><%loop> U: full-set S: full-set Exits: (-1 + %offset + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %nexti = add nsw i32 %i, 1
+; CHECK-NEXT:    --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: %numIterations LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %nexti2 = add nsw i32 %i2, 1
+; CHECK-NEXT:    --> {(1 + %offset),+,1}<nw><%loop> U: full-set S: full-set Exits: (%offset + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %ptr = getelementptr inbounds float, ptr %input, i32 %nexti2
+; CHECK-NEXT:    --> ((4 * (sext i32 {(1 + %offset),+,1}<nw><%loop> to i64))<nsw> + %input) U: full-set S: full-set Exits: ((4 * (sext i32 (%offset + %numIterations) to i64))<nsw> + %input) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test-add-not-header7
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is -1
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  br label %loop
+loop:
+  %i = phi i32 [ %nexti, %loop.latch ], [ 0, %entry ]
+  %i2 = phi i32 [ %nexti2, %loop.latch ], [ %offset, %entry ]
+  br label %loop2
+loop2:
+  %nexti = add nsw i32 %i, 1
+  %nexti2 = add nsw i32 %i2, 1
+  %ptr = getelementptr inbounds float, ptr %input, i32 %nexti2
+  %f = load float, ptr %ptr, align 4
+  %exitcond = icmp eq i32 %nexti, %numIterations
+  br i1 %exitcond, label %exit, label %loop.latch
+loop.latch:
+  br label %loop
+exit:
+  ret void
+}
+
+; Variant where the load is after the exit.
+define void @test-add-not-header8(ptr %input, i32 %offset, i32 %numIterations) {
+; CHECK-LABEL: 'test-add-not-header8'
+; CHECK-NEXT:  Classifying expressions for: @test-add-not-header8
+; CHECK-NEXT:    %i = phi i32 [ %nexti, %loop.latch ], [ 0, %entry ]
+; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %i2 = phi i32 [ %nexti2, %loop.latch ], [ %offset, %entry ]
+; CHECK-NEXT:    --> {%offset,+,1}<nsw><%loop> U: full-set S: full-set Exits: (-1 + %offset + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %nexti = add nsw i32 %i, 1
+; CHECK-NEXT:    --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: %numIterations LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %nexti2 = add nsw i32 %i2, 1
+; CHECK-NEXT:    --> {(1 + %offset),+,1}<nw><%loop> U: full-set S: full-set Exits: (%offset + %numIterations) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %ptr = getelementptr inbounds float, ptr %input, i32 %nexti2
+; CHECK-NEXT:    --> ((4 * (sext i32 {(1 + %offset),+,1}<nw><%loop> to i64))<nsw> + %input) U: full-set S: full-set Exits: ((4 * (sext i32 (%offset + %numIterations) to i64))<nsw> + %input) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test-add-not-header8
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is -1
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + %numIterations)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  br label %loop
+loop:
+  %i = phi i32 [ %nexti, %loop.latch ], [ 0, %entry ]
+  %i2 = phi i32 [ %nexti2, %loop.latch ], [ %offset, %entry ]
+  br label %loop2
+loop2:
+  %nexti = add nsw i32 %i, 1
+  %nexti2 = add nsw i32 %i2, 1
+  %exitcond = icmp eq i32 %nexti, %numIterations
+  br i1 %exitcond, label %exit, label %loop.latch
+loop.latch:
+  %ptr = getelementptr inbounds float, ptr %input, i32 %nexti2
+  %f = load float, ptr %ptr, align 4
+  br label %loop
+exit:
+  ret void
+}
+
 ; The call instruction makes it not guaranteed that the add will be
 ; executed, since it could run forever or throw an exception, so we
 ; cannot assume that the UB is realized.


        


More information about the llvm-commits mailing list