Skip to content

Commit

Permalink
[SCEV] Add additional tests for addrec nowrap flags (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Apr 18, 2023
1 parent c30c5f0 commit 3e50896
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3e50896

Please sign in to comment.