blob: 0d5681b539a7d9c4226c86db4e5a05d60c36ac11 [file] [log] [blame]
Michael Zolotukhinb2738e42016-08-02 21:24:14 +00001; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll -unroll-runtime-epilog=true | FileCheck %s -check-prefix=EPILOG
Evgeny Stupachenko23ce61b2016-04-27 03:04:54 +00002; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll -unroll-runtime-epilog=false | FileCheck %s -check-prefix=PROLOG
Michael Zolotukhin0dcae712014-11-20 20:19:55 +00003target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4
Sanjoy Das11b279a2015-02-18 19:32:25 +00005; This test case documents how runtime loop unrolling handles the case
6; when the backedge-count is -1.
7
8; If %N, the backedge-taken count, is -1 then %0 unsigned-overflows
9; and is 0. %xtraiter too is 0, signifying that the total trip-count
10; is divisible by 2. The prologue then branches to the unrolled loop
11; and executes the 2^32 iterations there, in groups of 2.
12
Evgeny Stupachenko23ce61b2016-04-27 03:04:54 +000013; EPILOG: entry:
Sanjoy Das11b279a2015-02-18 19:32:25 +000014
Evgeny Stupachenko23ce61b2016-04-27 03:04:54 +000015; EPILOG-NEXT: %0 = add i32 %N, 1
16; EPILOG-NEXT: %xtraiter = and i32 %0, 1
17; EPILOG-NEXT: %1 = icmp ult i32 %N, 1
18; EPILOG-NEXT: br i1 %1, label %while.end.unr-lcssa, label %entry.new
19; EPILOG: while.body:
Sanjoy Das11b279a2015-02-18 19:32:25 +000020
Evgeny Stupachenko23ce61b2016-04-27 03:04:54 +000021; EPILOG: %lcmp.mod = icmp ne i32 %xtraiter, 0
22; EPILOG-NEXT: br i1 %lcmp.mod, label %while.body.epil.preheader, label %while.end
23; EPILOG: while.body.epil:
Sanjoy Das11b279a2015-02-18 19:32:25 +000024
Evgeny Stupachenko23ce61b2016-04-27 03:04:54 +000025; PROLOG: entry:
26; PROLOG-NEXT: %0 = add i32 %N, 1
27; PROLOG-NEXT: %xtraiter = and i32 %0, 1
28; PROLOG-NEXT: %lcmp.mod = icmp ne i32 %xtraiter, 0
29; PROLOG-NEXT: br i1 %lcmp.mod, label %while.body.prol.preheader, label %while.body.prol.loopexit
30; PROLOG: while.body.prol:
31
32; PROLOG: %1 = icmp ult i32 %N, 1
33; PROLOG-NEXT: br i1 %1, label %while.end, label %entry.new
34; PROLOG: while.body:
Michael Zolotukhin0dcae712014-11-20 20:19:55 +000035
36; Function Attrs: nounwind readnone ssp uwtable
Sanjoy Das11b279a2015-02-18 19:32:25 +000037define i32 @foo(i32 %N) {
Michael Zolotukhin0dcae712014-11-20 20:19:55 +000038entry:
39 br label %while.body
40
41while.body: ; preds = %while.body, %entry
42 %i = phi i32 [ 0, %entry ], [ %inc, %while.body ]
43 %cmp = icmp eq i32 %i, %N
44 %inc = add i32 %i, 1
45 br i1 %cmp, label %while.end, label %while.body
46
47while.end: ; preds = %while.body
48 ret i32 %i
49}