Krzysztof Parzyszek | 78cc36f | 2015-03-18 15:56:43 +0000 | [diff] [blame] | 1 | ; RUN: llc -march=hexagon -mcpu=hexagonv4 -no-phi-elim-live-out-early-exit \ |
| 2 | ; RUN: < %s | FileCheck %s |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 3 | ; Check that we remove the compare and induction variable instructions |
| 4 | ; after generating hardware loops. |
| 5 | ; Bug 6685. |
| 6 | |
| 7 | ; CHECK: loop0 |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame^] | 8 | ; CHECK-NOT: r{{[0-9]+}} = add(r{{[0-9]+}},#-1) |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 9 | ; CHECK-NOT: cmp.eq |
| 10 | ; CHECK: endloop0 |
| 11 | |
| 12 | define i32 @test1(i32* nocapture %b, i32 %n) nounwind readonly { |
| 13 | entry: |
| 14 | %cmp1 = icmp sgt i32 %n, 0 |
| 15 | br i1 %cmp1, label %for.body.preheader, label %for.end |
| 16 | |
| 17 | for.body.preheader: |
| 18 | br label %for.body |
| 19 | |
| 20 | for.body: ; preds = %for.body.preheader, %for.body |
| 21 | %sum.03 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ] |
| 22 | %arrayidx.phi = phi i32* [ %arrayidx.inc, %for.body ], [ %b, %for.body.preheader ] |
| 23 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ] |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 24 | %0 = load i32, i32* %arrayidx.phi, align 4 |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 25 | %add = add nsw i32 %0, %sum.03 |
| 26 | %inc = add nsw i32 %i.02, 1 |
| 27 | %exitcond = icmp eq i32 %inc, %n |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 28 | %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1 |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 29 | br i1 %exitcond, label %for.end.loopexit, label %for.body |
| 30 | |
| 31 | for.end.loopexit: |
| 32 | br label %for.end |
| 33 | |
| 34 | for.end: |
| 35 | %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ] |
| 36 | ret i32 %sum.0.lcssa |
| 37 | } |
| 38 | |
| 39 | ; This test checks that that initial loop count value is removed. |
| 40 | ; CHECK-NOT: ={{.}}#40 |
| 41 | ; CHECK: loop0 |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame^] | 42 | ; CHECK-NOT: r{{[0-9]+}} = add(r{{[0-9]+}},#-1) |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 43 | ; CHECK-NOT: cmp.eq |
| 44 | ; CHECK: endloop0 |
| 45 | |
| 46 | define i32 @test2(i32* nocapture %b) nounwind readonly { |
| 47 | entry: |
| 48 | br label %for.body |
| 49 | |
| 50 | for.body: |
| 51 | %sum.02 = phi i32 [ 0, %entry ], [ %add, %for.body ] |
| 52 | %arrayidx.phi = phi i32* [ %b, %entry ], [ %arrayidx.inc, %for.body ] |
| 53 | %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 54 | %0 = load i32, i32* %arrayidx.phi, align 4 |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 55 | %add = add nsw i32 %0, %sum.02 |
| 56 | %inc = add nsw i32 %i.01, 1 |
| 57 | %exitcond = icmp eq i32 %inc, 40 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 58 | %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1 |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 59 | br i1 %exitcond, label %for.end, label %for.body |
| 60 | |
| 61 | for.end: |
| 62 | ret i32 %add |
| 63 | } |
| 64 | |
| 65 | ; This test checks that we don't remove the induction variable since it's used. |
| 66 | ; CHECK: loop0 |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame^] | 67 | ; CHECK: r{{[0-9]+}} = add(r{{[0-9]+}},#1) |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 68 | ; CHECK-NOT: cmp.eq |
| 69 | ; CHECK: endloop0 |
| 70 | define i32 @test3(i32* nocapture %b) nounwind { |
| 71 | entry: |
| 72 | br label %for.body |
| 73 | |
| 74 | for.body: |
| 75 | %arrayidx.phi = phi i32* [ %b, %entry ], [ %arrayidx.inc, %for.body ] |
| 76 | %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] |
| 77 | store i32 %i.01, i32* %arrayidx.phi, align 4 |
| 78 | %inc = add nsw i32 %i.01, 1 |
| 79 | %exitcond = icmp eq i32 %inc, 40 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 80 | %arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1 |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 81 | br i1 %exitcond, label %for.end, label %for.body |
| 82 | |
| 83 | for.end: |
| 84 | ret i32 0 |
| 85 | } |
| 86 | |
| 87 | |