Fix a trip-count overflow issue in LoopUnroll.
[oota-llvm.git] / test / Transforms / LoopUnroll / tripcount-overflow.ll
1 ; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll | FileCheck %s
2 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3
4 ; When prologue is fully unrolled, the branch on its end is unconditional.
5 ; Unrolling it is illegal if we can't prove that trip-count+1 doesn't overflow,
6 ; like in this example, where it comes from an argument.
7 ;
8 ; This test is based on an example from here:
9 ; http://stackoverflow.com/questions/23838661/why-is-clang-optimizing-this-code-out
10 ;
11 ; CHECK: while.body.prol:
12 ; CHECK: br i1
13 ; CHECK: entry.split:
14
15 ; Function Attrs: nounwind readnone ssp uwtable
16 define i32 @foo(i32 %N) #0 {
17 entry:
18   br label %while.body
19
20 while.body:                                       ; preds = %while.body, %entry
21   %i = phi i32 [ 0, %entry ], [ %inc, %while.body ]
22   %cmp = icmp eq i32 %i, %N
23   %inc = add i32 %i, 1
24   br i1 %cmp, label %while.end, label %while.body
25
26 while.end:                                        ; preds = %while.body
27   ret i32 %i
28 }
29
30 attributes #0 = { nounwind readnone ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }