1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s
3 ; LSR used to pick a sub-optimal solution due to the target responding
4 ; conservatively to isLegalAddImmediate for negative values.
8 define void @test(i32 %px) {
10 ; CHECK: // %bb.0: // %entry
11 ; CHECK-NEXT: str x30, [sp, #-32]! // 8-byte Folded Spill
12 ; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
13 ; CHECK-NEXT: .cfi_def_cfa_offset 32
14 ; CHECK-NEXT: .cfi_offset w19, -8
15 ; CHECK-NEXT: .cfi_offset w20, -16
16 ; CHECK-NEXT: .cfi_offset w30, -32
17 ; CHECK-NEXT: subs w8, w0, #1
18 ; CHECK-NEXT: mov w19, w0
19 ; CHECK-NEXT: csel w20, wzr, w8, lt
20 ; CHECK-NEXT: b .LBB0_2
21 ; CHECK-NEXT: .LBB0_1: // %for.inc
22 ; CHECK-NEXT: // in Loop: Header=BB0_2 Depth=1
23 ; CHECK-NEXT: cmp w20, w19
24 ; CHECK-NEXT: add w20, w20, #1
25 ; CHECK-NEXT: b.gt .LBB0_4
26 ; CHECK-NEXT: .LBB0_2: // %for.body
27 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
28 ; CHECK-NEXT: cmp w19, w20
29 ; CHECK-NEXT: b.eq .LBB0_1
30 ; CHECK-NEXT: // %bb.3: // %if.then3
31 ; CHECK-NEXT: // in Loop: Header=BB0_2 Depth=1
32 ; CHECK-NEXT: mov w0, w20
34 ; CHECK-NEXT: b .LBB0_1
35 ; CHECK-NEXT: .LBB0_4: // %for.cond.cleanup
36 ; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
37 ; CHECK-NEXT: ldr x30, [sp], #32 // 8-byte Folded Reload
40 %sub = add nsw i32 %px, -1
41 %cmp = icmp slt i32 %px, 1
42 %.sub = select i1 %cmp, i32 0, i32 %sub
46 %x.015 = phi i32 [ %inc, %for.inc ], [ %.sub, %entry ]
47 %cmp2 = icmp eq i32 %x.015, %px
48 br i1 %cmp2, label %for.inc, label %if.then3
51 tail call void @foo(i32 %x.015)
55 %inc = add nsw i32 %x.015, 1
56 %cmp1 = icmp sgt i32 %x.015, %px
57 br i1 %cmp1, label %for.cond.cleanup.loopexit, label %for.body
59 for.cond.cleanup.loopexit:
60 br label %for.cond.cleanup