mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-30 16:33:57 +00:00
bac5341e94
The way we elide max expressions when computing trip counts is incorrect -- it breaks cases like this: ``` static int wrapping_add(int a, int b) { return (int)((unsigned)a + (unsigned)b); } void test() { volatile int end_buf = 2147483548; // INT_MIN - 100 int end = end_buf; unsigned counter = 0; for (int start = wrapping_add(end, 200); start < end; start++) counter++; print(counter); } ``` Note: the `NoWrap` variable that was being tested has little to do with the values flowing into the max expression; it is a property of the induction variable. test/Transforms/LoopUnroll/nsw-tripcount.ll was added to solely test functionality I'm reverting in this change, so I've deleted the test fully. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273079 91177308-0d34-0410-b5e6-96231b3b80d8
82 lines
2.3 KiB
LLVM
82 lines
2.3 KiB
LLVM
; RUN: opt -S -analyze -scalar-evolution < %s | FileCheck %s
|
|
|
|
define void @u_0(i8 %rhs) {
|
|
; E.g.: %rhs = 255, %start = 99, backedge taken 156 times
|
|
entry:
|
|
%start = add i8 %rhs, 100
|
|
br label %loop
|
|
|
|
loop:
|
|
%iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
|
|
%iv.inc = add nuw i8 %iv, 1 ;; Note: this never unsigned-wraps
|
|
%iv.cmp = icmp ult i8 %iv, %rhs
|
|
br i1 %iv.cmp, label %loop, label %leave
|
|
|
|
; CHECK-LABEL: Determining loop execution counts for: @u_0
|
|
; CHECK-NEXT: Loop %loop: backedge-taken count is (-100 + (-1 * %rhs) + ((100 + %rhs) umax %rhs))
|
|
; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
|
|
|
|
leave:
|
|
ret void
|
|
}
|
|
|
|
define void @u_1(i8 %start) {
|
|
entry:
|
|
; E.g.: %start = 99, %rhs = 255, backedge taken 156 times
|
|
%rhs = add i8 %start, -100
|
|
br label %loop
|
|
|
|
loop:
|
|
%iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
|
|
%iv.inc = add nuw i8 %iv, 1 ;; Note: this never unsigned-wraps
|
|
%iv.cmp = icmp ult i8 %iv, %rhs
|
|
br i1 %iv.cmp, label %loop, label %leave
|
|
|
|
; CHECK-LABEL: Determining loop execution counts for: @u_1
|
|
; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + ((-100 + %start) umax %start))
|
|
; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
|
|
|
|
leave:
|
|
ret void
|
|
}
|
|
|
|
define void @s_0(i8 %rhs) {
|
|
entry:
|
|
; E.g.: %rhs = 127, %start = -29, backedge taken 156 times
|
|
%start = add i8 %rhs, 100
|
|
br label %loop
|
|
|
|
loop:
|
|
%iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
|
|
%iv.inc = add nsw i8 %iv, 1 ;; Note: this never signed-wraps
|
|
%iv.cmp = icmp slt i8 %iv, %rhs
|
|
br i1 %iv.cmp, label %loop, label %leave
|
|
|
|
; CHECK-LABEL: Determining loop execution counts for: @s_0
|
|
; CHECK-NEXT: Loop %loop: backedge-taken count is (-100 + (-1 * %rhs) + ((100 + %rhs) smax %rhs))
|
|
; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
|
|
|
|
leave:
|
|
ret void
|
|
}
|
|
|
|
define void @s_1(i8 %start) {
|
|
entry:
|
|
; E.g.: start = -29, %rhs = 127, %backedge taken 156 times
|
|
%rhs = add i8 %start, -100
|
|
br label %loop
|
|
|
|
loop:
|
|
%iv = phi i8 [ %start, %entry ], [ %iv.inc, %loop ]
|
|
%iv.inc = add nsw i8 %iv, 1
|
|
%iv.cmp = icmp slt i8 %iv, %rhs
|
|
br i1 %iv.cmp, label %loop, label %leave
|
|
|
|
; CHECK-LABEL: Determining loop execution counts for: @s_1
|
|
; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + ((-100 + %start) smax %start))
|
|
; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
|
|
|
|
leave:
|
|
ret void
|
|
}
|