Michael Zolotukhin | b2738e4 | 2016-08-02 21:24:14 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll -unroll-runtime-epilog=true | FileCheck %s -check-prefix=EPILOG |
Evgeny Stupachenko | 23ce61b | 2016-04-27 03:04:54 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -S -unroll-runtime -unroll-count=2 -loop-unroll -unroll-runtime-epilog=false | FileCheck %s -check-prefix=PROLOG |
Michael Zolotukhin | 0dcae71 | 2014-11-20 20:19:55 +0000 | [diff] [blame] | 3 | target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" |
| 4 | |
Sanjoy Das | 11b279a | 2015-02-18 19:32:25 +0000 | [diff] [blame] | 5 | ; 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 Stupachenko | 23ce61b | 2016-04-27 03:04:54 +0000 | [diff] [blame] | 13 | ; EPILOG: entry: |
Sanjoy Das | 11b279a | 2015-02-18 19:32:25 +0000 | [diff] [blame] | 14 | |
Evgeny Stupachenko | 23ce61b | 2016-04-27 03:04:54 +0000 | [diff] [blame] | 15 | ; 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 Das | 11b279a | 2015-02-18 19:32:25 +0000 | [diff] [blame] | 20 | |
Evgeny Stupachenko | 23ce61b | 2016-04-27 03:04:54 +0000 | [diff] [blame] | 21 | ; 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 Das | 11b279a | 2015-02-18 19:32:25 +0000 | [diff] [blame] | 24 | |
Evgeny Stupachenko | 23ce61b | 2016-04-27 03:04:54 +0000 | [diff] [blame] | 25 | ; 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 Zolotukhin | 0dcae71 | 2014-11-20 20:19:55 +0000 | [diff] [blame] | 35 | |
| 36 | ; Function Attrs: nounwind readnone ssp uwtable |
Sanjoy Das | 11b279a | 2015-02-18 19:32:25 +0000 | [diff] [blame] | 37 | define i32 @foo(i32 %N) { |
Michael Zolotukhin | 0dcae71 | 2014-11-20 20:19:55 +0000 | [diff] [blame] | 38 | entry: |
| 39 | br label %while.body |
| 40 | |
| 41 | while.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 | |
| 47 | while.end: ; preds = %while.body |
| 48 | ret i32 %i |
| 49 | } |