blob: ee95f37c203cd0d0b7c627dce0a3c4615f334164 [file] [log] [blame]
Geoff Berry486f49c2016-06-07 16:48:43 +00001; 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
5declare void @foo(i32)
6
7define void @test(i32 %px) {
8; CHECK_LABEL: test:
9; CHECK_LABEL: %entry
Geoff Berrya2b90112018-02-27 16:59:10 +000010; CHECK: subs [[REG0:w[0-9]+]],
11; CHECK: csel {{w[0-9]+}}, wzr, [[REG0]]
Geoff Berry486f49c2016-06-07 16:48:43 +000012entry:
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
18for.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
27if.then3:
28 tail call void @foo(i32 %x.015)
29 br label %for.inc
30
31for.inc:
32; CHECK_LABEL: %for.inc
Matthias Braun325cd2c2016-11-11 01:34:21 +000033; CHECK: cmp
34; CHECK-NEXT: add
35; CHECK-NEXT: b.le
Geoff Berry486f49c2016-06-07 16:48:43 +000036; 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
41for.cond.cleanup.loopexit:
42 br label %for.cond.cleanup
43
44for.cond.cleanup:
45 ret void
46}