mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:43:36 +01:00
19ad020e28
A backedge-taken count doesn't refer to memory; returning a pointer type is nonsense. So make sure we always return an integer. The obvious way to do this would be to just convert the operands of the icmp to integers, but that doesn't quite work out at the moment: isLoopEntryGuardedByCond currently gets confused by ptrtoint operations. So we perform the ptrtoint conversion late for lt/gt operations. The test changes are mostly innocuous. The most interesting changes are more complex SCEV expressions of the form "(-1 * (ptrtoint i8* %ptr to i64)) + %ptr)". This is expected: we can't fold this to zero because we need to preserve the pointer base. The call to isLoopEntryGuardedByCond in howFarToZero is less precise because of ptrtoint operations; this shows up in the function pr46786_c26_char in ptrtoint.ll. Fixing it here would require more complex refactoring. It should eventually be fixed by future improvements to isImpliedCond. See https://bugs.llvm.org/show_bug.cgi?id=46786 for context. Differential Revision: https://reviews.llvm.org/D103656
129 lines
7.5 KiB
LLVM
129 lines
7.5 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
|
|
; RUN: opt < %s -S -scalar-evolution-use-expensive-range-sharpening -analyze -scalar-evolution -enable-new-pm=0 | FileCheck %s
|
|
; RUN: opt < %s -S -scalar-evolution-use-expensive-range-sharpening -passes='print<scalar-evolution>' 2>&1 | FileCheck %s
|
|
|
|
define i32 @test_01(i32 %start, i32* %p, i32* %q) {
|
|
; CHECK-LABEL: 'test_01'
|
|
; CHECK-NEXT: Classifying expressions for: @test_01
|
|
; CHECK-NEXT: %0 = zext i32 %start to i64
|
|
; CHECK-NEXT: --> (zext i32 %start to i64) U: [0,4294967296) S: [0,4294967296)
|
|
; CHECK-NEXT: %indvars.iv = phi i64 [ %indvars.iv.next, %backedge ], [ %0, %entry ]
|
|
; CHECK-NEXT: --> {(zext i32 %start to i64),+,-1}<nsw><%loop> U: [0,4294967296) S: [0,4294967296) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %iv = phi i32 [ %start, %entry ], [ %iv.next, %backedge ]
|
|
; CHECK-NEXT: --> {%start,+,-1}<%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %iv.next = add i32 %iv, -1
|
|
; CHECK-NEXT: --> {(-1 + %start),+,-1}<%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %index = zext i32 %iv.next to i64
|
|
; CHECK-NEXT: --> (zext i32 {(-1 + %start),+,-1}<%loop> to i64) U: [0,4294967296) S: [0,4294967296) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %store.addr = getelementptr i32, i32* %p, i64 %index
|
|
; CHECK-NEXT: --> ((4 * (zext i32 {(-1 + %start),+,-1}<%loop> to i64))<nuw><nsw> + %p) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %load.addr = getelementptr i32, i32* %q, i64 %index
|
|
; CHECK-NEXT: --> ((4 * (zext i32 {(-1 + %start),+,-1}<%loop> to i64))<nuw><nsw> + %q) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %stop = load i32, i32* %load.addr, align 4
|
|
; CHECK-NEXT: --> %stop U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
|
|
; CHECK-NEXT: %indvars.iv.next = add nsw i64 %indvars.iv, -1
|
|
; CHECK-NEXT: --> {(-1 + (zext i32 %start to i64))<nsw>,+,-1}<nsw><%loop> U: [-4294967296,4294967295) S: [-1,4294967295) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: Determining loop execution counts for: @test_01
|
|
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
|
|
; CHECK-NEXT: exit count for loop: (zext i32 %start to i64)
|
|
; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
|
|
; CHECK-NEXT: Loop %loop: max backedge-taken count is 4294967295
|
|
; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
|
|
;
|
|
entry:
|
|
%0 = zext i32 %start to i64
|
|
br label %loop
|
|
|
|
loop: ; preds = %backedge, %entry
|
|
%indvars.iv = phi i64 [ %indvars.iv.next, %backedge ], [ %0, %entry ]
|
|
%iv = phi i32 [ %start, %entry ], [ %iv.next, %backedge ]
|
|
%cond = icmp eq i64 %indvars.iv, 0
|
|
br i1 %cond, label %exit, label %backedge
|
|
|
|
backedge: ; preds = %loop
|
|
%iv.next = add i32 %iv, -1
|
|
%index = zext i32 %iv.next to i64
|
|
%store.addr = getelementptr i32, i32* %p, i64 %index
|
|
store i32 1, i32* %store.addr, align 4
|
|
%load.addr = getelementptr i32, i32* %q, i64 %index
|
|
%stop = load i32, i32* %load.addr, align 4
|
|
%loop.cond = icmp eq i32 %stop, 0
|
|
%indvars.iv.next = add nsw i64 %indvars.iv, -1
|
|
br i1 %loop.cond, label %loop, label %failure
|
|
|
|
exit: ; preds = %loop
|
|
ret i32 0
|
|
|
|
failure: ; preds = %backedge
|
|
unreachable
|
|
}
|
|
|
|
; Check that we do not mess up with wrapping ranges.
|
|
define i32 @test_02(i32 %start, i32* %p, i32* %q) {
|
|
; CHECK-LABEL: 'test_02'
|
|
; CHECK-NEXT: Classifying expressions for: @test_02
|
|
; CHECK-NEXT: %zext = zext i32 %start to i64
|
|
; CHECK-NEXT: --> (zext i32 %start to i64) U: [0,4294967296) S: [0,4294967296)
|
|
; CHECK-NEXT: %shl = shl i64 %zext, 31
|
|
; CHECK-NEXT: --> (2147483648 * (zext i32 %start to i64))<nuw><nsw> U: [0,9223372034707292161) S: [0,9223372034707292161)
|
|
; CHECK-NEXT: %indvars.iv = phi i64 [ %indvars.iv.next, %loop ], [ %shl, %entry ]
|
|
; CHECK-NEXT: --> {(2147483648 * (zext i32 %start to i64))<nuw><nsw>,+,-1}<nsw><%loop> U: [-9223372036854775808,9223372034707292161) S: [-9223372036854775808,9223372034707292161) Exits: -9223372036854775806 LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %indvars.iv.next = add nsw i64 %indvars.iv, -1
|
|
; CHECK-NEXT: --> {(-1 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nsw>,+,-1}<nw><%loop> U: full-set S: full-set Exits: -9223372036854775807 LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: Determining loop execution counts for: @test_02
|
|
; CHECK-NEXT: Loop %loop: backedge-taken count is (9223372036854775806 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nuw>
|
|
; CHECK-NEXT: Loop %loop: max backedge-taken count is -2147483650
|
|
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (9223372036854775806 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nuw>
|
|
; CHECK-NEXT: Predicates:
|
|
; CHECK: Loop %loop: Trip multiple is 1
|
|
;
|
|
entry:
|
|
%zext = zext i32 %start to i64
|
|
%shl = shl i64 %zext, 31
|
|
br label %loop
|
|
|
|
loop: ; preds = %backedge, %entry
|
|
%indvars.iv = phi i64 [ %indvars.iv.next, %loop ], [ %shl, %entry ]
|
|
%cond = icmp eq i64 %indvars.iv, -9223372036854775806
|
|
%indvars.iv.next = add nsw i64 %indvars.iv, -1
|
|
br i1 %cond, label %exit, label %loop
|
|
|
|
exit: ; preds = %loop
|
|
ret i32 0
|
|
}
|
|
|
|
define void @pointer_iv_nowrap(i8* %startptr, i8* %endptr) local_unnamed_addr {
|
|
; CHECK-LABEL: 'pointer_iv_nowrap'
|
|
; CHECK-NEXT: Classifying expressions for: @pointer_iv_nowrap
|
|
; CHECK-NEXT: %init = getelementptr inbounds i8, i8* %startptr, i64 2000
|
|
; CHECK-NEXT: --> (2000 + %startptr)<nuw> U: [2000,0) S: [2000,0)
|
|
; CHECK-NEXT: %iv = phi i8* [ %init, %entry ], [ %iv.next, %loop ]
|
|
; CHECK-NEXT: --> {(2000 + %startptr)<nuw>,+,1}<nuw><%loop> U: [2000,0) S: [2000,0) Exits: ((-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)) + %startptr) LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: %iv.next = getelementptr inbounds i8, i8* %iv, i64 1
|
|
; CHECK-NEXT: --> {(2001 + %startptr)<nuw>,+,1}<nuw><%loop> U: [2001,0) S: [2001,0) Exits: (1 + (-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)) + %startptr) LoopDispositions: { %loop: Computable }
|
|
; CHECK-NEXT: Determining loop execution counts for: @pointer_iv_nowrap
|
|
; CHECK-NEXT: Loop %loop: backedge-taken count is (-2000 + (-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)))
|
|
; CHECK-NEXT: Loop %loop: max backedge-taken count is -2001
|
|
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-2000 + (-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)))
|
|
; CHECK-NEXT: Predicates:
|
|
; CHECK: Loop %loop: Trip multiple is 1
|
|
;
|
|
entry:
|
|
%init = getelementptr inbounds i8, i8* %startptr, i64 2000
|
|
br label %loop
|
|
|
|
loop:
|
|
%iv = phi i8* [ %init, %entry ], [ %iv.next, %loop ]
|
|
%iv.next = getelementptr inbounds i8, i8* %iv, i64 1
|
|
%ec = icmp ugt i8* %iv.next, %endptr
|
|
br i1 %ec, label %end, label %loop
|
|
|
|
end:
|
|
ret void
|
|
}
|
|
|
|
define i32 @dummy(i32 %start, i32* %p, i32* %q) {
|
|
entry:
|
|
ret i32 0
|
|
}
|