xref: /aosp_15_r20/external/llvm/test/Transforms/LoopUnroll/tripcount-overflow.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll | FileCheck %s -check-prefix=EPILOG
2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll -unroll-runtime-epilog=false | FileCheck %s -check-prefix=PROLOG
3*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; This test case documents how runtime loop unrolling handles the case
6*9880d681SAndroid Build Coastguard Worker; when the backedge-count is -1.
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker; If %N, the backedge-taken count, is -1 then %0 unsigned-overflows
9*9880d681SAndroid Build Coastguard Worker; and is 0.  %xtraiter too is 0, signifying that the total trip-count
10*9880d681SAndroid Build Coastguard Worker; is divisible by 2.  The prologue then branches to the unrolled loop
11*9880d681SAndroid Build Coastguard Worker; and executes the 2^32 iterations there, in groups of 2.
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker; EPILOG: entry:
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Worker; EPILOG-NEXT: %0 = add i32 %N, 1
16*9880d681SAndroid Build Coastguard Worker; EPILOG-NEXT: %xtraiter = and i32 %0, 1
17*9880d681SAndroid Build Coastguard Worker; EPILOG-NEXT: %1 = icmp ult i32 %N, 1
18*9880d681SAndroid Build Coastguard Worker; EPILOG-NEXT: br i1 %1, label %while.end.unr-lcssa, label %entry.new
19*9880d681SAndroid Build Coastguard Worker; EPILOG: while.body:
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker; EPILOG: %lcmp.mod = icmp ne i32 %xtraiter, 0
22*9880d681SAndroid Build Coastguard Worker; EPILOG-NEXT: br i1 %lcmp.mod, label %while.body.epil.preheader, label %while.end
23*9880d681SAndroid Build Coastguard Worker; EPILOG: while.body.epil:
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; PROLOG: entry:
26*9880d681SAndroid Build Coastguard Worker; PROLOG-NEXT: %0 = add i32 %N, 1
27*9880d681SAndroid Build Coastguard Worker; PROLOG-NEXT: %xtraiter = and i32 %0, 1
28*9880d681SAndroid Build Coastguard Worker; PROLOG-NEXT: %lcmp.mod = icmp ne i32 %xtraiter, 0
29*9880d681SAndroid Build Coastguard Worker; PROLOG-NEXT: br i1 %lcmp.mod, label %while.body.prol.preheader, label %while.body.prol.loopexit
30*9880d681SAndroid Build Coastguard Worker; PROLOG: while.body.prol:
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker; PROLOG: %1 = icmp ult i32 %N, 1
33*9880d681SAndroid Build Coastguard Worker; PROLOG-NEXT: br i1 %1, label %while.end, label %entry.new
34*9880d681SAndroid Build Coastguard Worker; PROLOG: while.body:
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone ssp uwtable
37*9880d681SAndroid Build Coastguard Workerdefine i32 @foo(i32 %N) {
38*9880d681SAndroid Build Coastguard Workerentry:
39*9880d681SAndroid Build Coastguard Worker  br label %while.body
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Workerwhile.body:                                       ; preds = %while.body, %entry
42*9880d681SAndroid Build Coastguard Worker  %i = phi i32 [ 0, %entry ], [ %inc, %while.body ]
43*9880d681SAndroid Build Coastguard Worker  %cmp = icmp eq i32 %i, %N
44*9880d681SAndroid Build Coastguard Worker  %inc = add i32 %i, 1
45*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %while.end, label %while.body
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Workerwhile.end:                                        ; preds = %while.body
48*9880d681SAndroid Build Coastguard Worker  ret i32 %i
49*9880d681SAndroid Build Coastguard Worker}
50