1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00
llvm-mirror/test/Analysis/ScalarEvolution/2008-11-18-Stride2.ll
Eli Friedman 05a71b0a6d [ScalarEvolution] Fix overflow in computeBECount.
The current implementation of computeBECount doesn't account for the
possibility that adding "Stride - 1" to Delta might overflow. For almost
all loops, it doesn't, but it's not actually proven anywhere.

To deal with this, use a variety of tricks to try to prove that the
addition doesn't overflow.  If the proof is impossible, use an alternate
sequence which never overflows.

Differential Revision: https://reviews.llvm.org/D105216
2021-07-16 16:15:18 -07:00

39 lines
1.4 KiB
LLVM

; RUN: opt < %s -analyze -enable-new-pm=0 -scalar-evolution 2>&1 | FileCheck %s
; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 2>&1 | FileCheck %s
; CHECK: Loop %bb: backedge-taken count is (((-3 + (-1 * (1 umin (-3 + (-1 * %x) + (1000 umax (3 + %x)))))<nuw><nsw> + (-1 * %x) + (1000 umax (3 + %x))) /u 3) + (1 umin (-3 + (-1 * %x) + (1000 umax (3 + %x)))))
; CHECK: Loop %bb: max backedge-taken count is 334
; This is a tricky testcase for unsigned wrap detection which ScalarEvolution
; doesn't yet know how to do.
define i32 @f(i32 %x) nounwind readnone {
entry:
%0 = icmp ugt i32 %x, 999 ; <i1> [#uses=1]
br i1 %0, label %bb2, label %bb.nph
bb.nph: ; preds = %entry
br label %bb
bb: ; preds = %bb.nph, %bb1
%indvar = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb1 ] ; <i32> [#uses=2]
%tmp = mul i32 %indvar, 3 ; <i32> [#uses=1]
%x_addr.04 = add i32 %tmp, %x ; <i32> [#uses=1]
%1 = add i32 %x_addr.04, 3 ; <i32> [#uses=2]
br label %bb1
bb1: ; preds = %bb
%2 = icmp ugt i32 %1, 999 ; <i1> [#uses=1]
%indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
br i1 %2, label %bb1.bb2_crit_edge, label %bb
bb1.bb2_crit_edge: ; preds = %bb1
%.lcssa = phi i32 [ %1, %bb1 ] ; <i32> [#uses=1]
br label %bb2
bb2: ; preds = %bb1.bb2_crit_edge, %entry
%x_addr.0.lcssa = phi i32 [ %.lcssa, %bb1.bb2_crit_edge ], [ %x, %entry ] ; <i32> [#uses=1]
ret i32 %x_addr.0.lcssa
}