blob: 5c250933af52e257b5d02124cf4bf7a7bf918f17 [file] [log] [blame]
Michael Zolotukhin0dcae712014-11-20 20:19:55 +00001; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll | FileCheck %s
2target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3
Sanjoy Das11b279a2015-02-18 19:32:25 +00004; This test case documents how runtime loop unrolling handles the case
5; when the backedge-count is -1.
6
7; If %N, the backedge-taken count, is -1 then %0 unsigned-overflows
8; and is 0. %xtraiter too is 0, signifying that the total trip-count
9; is divisible by 2. The prologue then branches to the unrolled loop
10; and executes the 2^32 iterations there, in groups of 2.
11
12
13; CHECK: entry:
14; CHECK-NEXT: %0 = add i32 %N, 1
15; CHECK-NEXT: %xtraiter = and i32 %0, 1
David L Kreitzer188de5a2016-04-05 12:19:35 +000016; CHECK-NEXT: %lcmp.mod = icmp ne i32 %xtraiter, %0
17; CHECK-NEXT: br i1 %lcmp.mod, label %entry.new, label %while.end.unr-lcssa
Sanjoy Das11b279a2015-02-18 19:32:25 +000018
David L Kreitzer188de5a2016-04-05 12:19:35 +000019; CHECK: while.body.epil:
20; CHECK: br label %while.end.epilog-lcssa
Sanjoy Das11b279a2015-02-18 19:32:25 +000021
David L Kreitzer188de5a2016-04-05 12:19:35 +000022; CHECK: while.end.epilog-lcssa:
Michael Zolotukhin0dcae712014-11-20 20:19:55 +000023
24; Function Attrs: nounwind readnone ssp uwtable
Sanjoy Das11b279a2015-02-18 19:32:25 +000025define i32 @foo(i32 %N) {
Michael Zolotukhin0dcae712014-11-20 20:19:55 +000026entry:
27 br label %while.body
28
29while.body: ; preds = %while.body, %entry
30 %i = phi i32 [ 0, %entry ], [ %inc, %while.body ]
31 %cmp = icmp eq i32 %i, %N
32 %inc = add i32 %i, 1
33 br i1 %cmp, label %while.end, label %while.body
34
35while.end: ; preds = %while.body
36 ret i32 %i
37}