| Sanjoy Das | 30c3538 | 2017-03-07 06:03:15 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -S -loop-unroll -unroll-threshold=4 | FileCheck %s | 
| Sanjoy Das | 664c925 | 2017-03-03 18:19:15 +0000 | [diff] [blame] | 2 |  | 
|  | 3 | define i32 @invariant_backedge_1(i32 %a, i32 %b) { | 
|  | 4 | ; CHECK-LABEL: @invariant_backedge_1 | 
|  | 5 | ; CHECK-NOT:     %plus = phi | 
|  | 6 | ; CHECK:       loop.peel: | 
|  | 7 | ; CHECK:       loop: | 
|  | 8 | ; CHECK:         %i = phi | 
|  | 9 | ; CHECK:         %sum = phi | 
|  | 10 | entry: | 
|  | 11 | br label %loop | 
|  | 12 |  | 
|  | 13 | loop: | 
|  | 14 | %i = phi i32 [ 0, %entry ], [ %inc, %loop ] | 
|  | 15 | %sum = phi i32 [ 0, %entry ], [ %incsum, %loop ] | 
|  | 16 | %plus = phi i32 [ %a, %entry ], [ %b, %loop ] | 
|  | 17 |  | 
|  | 18 | %incsum = add i32 %sum, %plus | 
|  | 19 | %inc = add i32 %i, 1 | 
|  | 20 | %cmp = icmp slt i32 %i, 1000 | 
| Sanjoy Das | 30c3538 | 2017-03-07 06:03:15 +0000 | [diff] [blame] | 21 |  | 
|  | 22 | br i1 %cmp, label %loop, label %exit | 
|  | 23 |  | 
|  | 24 | exit: | 
|  | 25 | ret i32 %sum | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | ; Peeling should fail due to method size. | 
|  | 29 | define i32 @invariant_backedge_2(i32 %a, i32 %b) { | 
|  | 30 | ; CHECK-LABEL: @invariant_backedge_2 | 
|  | 31 | ; CHECK-NOT:   loop.peel: | 
|  | 32 | ; CHECK:       loop: | 
|  | 33 | ; CHECK:         %i = phi | 
|  | 34 | ; CHECK:         %sum = phi | 
|  | 35 | ; CHECK:         %plus = phi | 
|  | 36 | entry: | 
|  | 37 | br label %loop | 
|  | 38 |  | 
|  | 39 | loop: | 
|  | 40 | %i = phi i32 [ 0, %entry ], [ %inc, %loop ] | 
|  | 41 | %sum = phi i32 [ 0, %entry ], [ %incsum2, %loop ] | 
|  | 42 | %plus = phi i32 [ %a, %entry ], [ %b, %loop ] | 
|  | 43 |  | 
|  | 44 | %incsum = add i32 %sum, %plus | 
|  | 45 | %incsum2 = add i32 %incsum, %plus | 
|  | 46 | %inc = add i32 %i, 1 | 
|  | 47 | %cmp = icmp slt i32 %i, 1000 | 
|  | 48 |  | 
| Sanjoy Das | 664c925 | 2017-03-03 18:19:15 +0000 | [diff] [blame] | 49 | br i1 %cmp, label %loop, label %exit | 
|  | 50 |  | 
|  | 51 | exit: | 
|  | 52 | ret i32 %sum | 
|  | 53 | } |