| Geoff Berry | 486f49c | 2016-06-07 16:48:43 +0000 | [diff] [blame] | 1 | ; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s |
| 2 | ; LSR used to pick a sub-optimal solution due to the target responding |
| 3 | ; conservatively to isLegalAddImmediate for negative values. |
| 4 | |
| 5 | declare void @foo(i32) |
| 6 | |
| 7 | define void @test(i32 %px) { |
| 8 | ; CHECK_LABEL: test: |
| 9 | ; CHECK_LABEL: %entry |
| Geoff Berry | a2b9011 | 2018-02-27 16:59:10 +0000 | [diff] [blame] | 10 | ; CHECK: subs [[REG0:w[0-9]+]], |
| 11 | ; CHECK: csel {{w[0-9]+}}, wzr, [[REG0]] |
| Geoff Berry | 486f49c | 2016-06-07 16:48:43 +0000 | [diff] [blame] | 12 | entry: |
| 13 | %sub = add nsw i32 %px, -1 |
| 14 | %cmp = icmp slt i32 %px, 1 |
| 15 | %.sub = select i1 %cmp, i32 0, i32 %sub |
| 16 | br label %for.body |
| 17 | |
| 18 | for.body: |
| 19 | ; CHECK_LABEL: %for.body |
| 20 | ; CHECK: cmp |
| 21 | ; CHECK-NEXT: b.eq |
| 22 | ; CHECK-LABEL: %if.then3 |
| 23 | %x.015 = phi i32 [ %inc, %for.inc ], [ %.sub, %entry ] |
| 24 | %cmp2 = icmp eq i32 %x.015, %px |
| 25 | br i1 %cmp2, label %for.inc, label %if.then3 |
| 26 | |
| 27 | if.then3: |
| 28 | tail call void @foo(i32 %x.015) |
| 29 | br label %for.inc |
| 30 | |
| 31 | for.inc: |
| 32 | ; CHECK_LABEL: %for.inc |
| Matthias Braun | 325cd2c | 2016-11-11 01:34:21 +0000 | [diff] [blame] | 33 | ; CHECK: cmp |
| 34 | ; CHECK-NEXT: add |
| 35 | ; CHECK-NEXT: b.le |
| Geoff Berry | 486f49c | 2016-06-07 16:48:43 +0000 | [diff] [blame] | 36 | ; CHECK_LABEL: %for.cond.cleanup |
| 37 | %inc = add nsw i32 %x.015, 1 |
| 38 | %cmp1 = icmp sgt i32 %x.015, %px |
| 39 | br i1 %cmp1, label %for.cond.cleanup.loopexit, label %for.body |
| 40 | |
| 41 | for.cond.cleanup.loopexit: |
| 42 | br label %for.cond.cleanup |
| 43 | |
| 44 | for.cond.cleanup: |
| 45 | ret void |
| 46 | } |