1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -debugify-and-strip-all-safe < %s -O3 -mtriple=aarch64-eabi -verify-machineinstrs | FileCheck %s
4 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5 target triple = "aarch64-linaro-linux-gnueabi"
7 ; CMN is an alias of ADDS.
9 define void @test_add_cbz(i32 %a, i32 %b, i32* %ptr) {
10 ; CHECK-LABEL: test_add_cbz:
11 ; CHECK: // %bb.0: // %common.ret
12 ; CHECK-NEXT: cmn w0, w1
13 ; CHECK-NEXT: cset w8, eq
14 ; CHECK-NEXT: str w8, [x2]
16 %c = add nsw i32 %a, %b
17 %d = icmp ne i32 %c, 0
18 br i1 %d, label %L1, label %L2
20 store i32 0, i32* %ptr, align 4
23 store i32 1, i32* %ptr, align 4
27 define void @test_add_cbz_multiple_use(i32 %a, i32 %b, i32* %ptr) {
28 ; CHECK-LABEL: test_add_cbz_multiple_use:
29 ; CHECK: // %bb.0: // %common.ret
30 ; CHECK-NEXT: adds w8, w0, w1
31 ; CHECK-NEXT: csel w8, wzr, w8, ne
32 ; CHECK-NEXT: str w8, [x2]
34 %c = add nsw i32 %a, %b
35 %d = icmp ne i32 %c, 0
36 br i1 %d, label %L1, label %L2
38 store i32 0, i32* %ptr, align 4
41 store i32 %c, i32* %ptr, align 4
45 define void @test_add_cbz_64(i64 %a, i64 %b, i64* %ptr) {
46 ; CHECK-LABEL: test_add_cbz_64:
47 ; CHECK: // %bb.0: // %common.ret
48 ; CHECK-NEXT: cmn x0, x1
49 ; CHECK-NEXT: cset w8, eq
50 ; CHECK-NEXT: str x8, [x2]
52 %c = add nsw i64 %a, %b
53 %d = icmp ne i64 %c, 0
54 br i1 %d, label %L1, label %L2
56 store i64 0, i64* %ptr, align 4
59 store i64 1, i64* %ptr, align 4
63 define void @test_and_cbz(i32 %a, i32* %ptr) {
64 ; CHECK-LABEL: test_and_cbz:
65 ; CHECK: // %bb.0: // %common.ret
66 ; CHECK-NEXT: tst w0, #0x6
67 ; CHECK-NEXT: cset w8, eq
68 ; CHECK-NEXT: str w8, [x1]
71 %d = icmp ne i32 %c, 0
72 br i1 %d, label %L1, label %L2
74 store i32 0, i32* %ptr, align 4
77 store i32 1, i32* %ptr, align 4
81 define void @test_bic_cbnz(i32 %a, i32 %b, i32* %ptr) {
82 ; CHECK-LABEL: test_bic_cbnz:
83 ; CHECK: // %bb.0: // %common.ret
84 ; CHECK-NEXT: bics wzr, w1, w0
85 ; CHECK-NEXT: cset w8, ne
86 ; CHECK-NEXT: str w8, [x2]
89 %d = icmp eq i32 %c, %b
90 br i1 %d, label %L1, label %L2
92 store i32 0, i32* %ptr, align 4
95 store i32 1, i32* %ptr, align 4
99 define void @test_add_tbz(i32 %a, i32 %b, i32* %ptr) {
100 ; CHECK-LABEL: test_add_tbz:
101 ; CHECK: // %bb.0: // %entry
102 ; CHECK-NEXT: adds w8, w0, w1
103 ; CHECK-NEXT: b.pl .LBB5_2
104 ; CHECK-NEXT: // %bb.1: // %L1
105 ; CHECK-NEXT: str w8, [x2]
106 ; CHECK-NEXT: .LBB5_2: // %L2
109 %add = add nsw i32 %a, %b
110 %cmp36 = icmp sge i32 %add, 0
111 br i1 %cmp36, label %L2, label %L1
113 store i32 %add, i32* %ptr, align 8
119 define void @test_subs_tbz(i32 %a, i32 %b, i32* %ptr) {
120 ; CHECK-LABEL: test_subs_tbz:
121 ; CHECK: // %bb.0: // %entry
122 ; CHECK-NEXT: subs w8, w0, w1
123 ; CHECK-NEXT: b.pl .LBB6_2
124 ; CHECK-NEXT: // %bb.1: // %L1
125 ; CHECK-NEXT: str w8, [x2]
126 ; CHECK-NEXT: .LBB6_2: // %L2
129 %sub = sub nsw i32 %a, %b
130 %cmp36 = icmp sge i32 %sub, 0
131 br i1 %cmp36, label %L2, label %L1
133 store i32 %sub, i32* %ptr, align 8
139 define void @test_add_tbnz(i32 %a, i32 %b, i32* %ptr) {
140 ; CHECK-LABEL: test_add_tbnz:
141 ; CHECK: // %bb.0: // %entry
142 ; CHECK-NEXT: adds w8, w0, w1
143 ; CHECK-NEXT: b.mi .LBB7_2
144 ; CHECK-NEXT: // %bb.1: // %L1
145 ; CHECK-NEXT: str w8, [x2]
146 ; CHECK-NEXT: .LBB7_2: // %L2
149 %add = add nsw i32 %a, %b
150 %cmp36 = icmp slt i32 %add, 0
151 br i1 %cmp36, label %L2, label %L1
153 store i32 %add, i32* %ptr, align 8
159 define void @test_subs_tbnz(i32 %a, i32 %b, i32* %ptr) {
160 ; CHECK-LABEL: test_subs_tbnz:
161 ; CHECK: // %bb.0: // %entry
162 ; CHECK-NEXT: subs w8, w0, w1
163 ; CHECK-NEXT: b.mi .LBB8_2
164 ; CHECK-NEXT: // %bb.1: // %L1
165 ; CHECK-NEXT: str w8, [x2]
166 ; CHECK-NEXT: .LBB8_2: // %L2
169 %sub = sub nsw i32 %a, %b
170 %cmp36 = icmp slt i32 %sub, 0
171 br i1 %cmp36, label %L2, label %L1
173 store i32 %sub, i32* %ptr, align 8
180 declare void @bar(i32)
182 ; Don't transform since the call will clobber the NZCV bits.
183 define void @test_call_clobber(i32 %unused, i32 %a) {
184 ; CHECK-LABEL: test_call_clobber:
185 ; CHECK: // %bb.0: // %entry
186 ; CHECK-NEXT: stp x30, x19, [sp, #-16]! // 16-byte Folded Spill
187 ; CHECK-NEXT: .cfi_def_cfa_offset 16
188 ; CHECK-NEXT: .cfi_offset w19, -8
189 ; CHECK-NEXT: .cfi_offset w30, -16
190 ; CHECK-NEXT: and w19, w1, #0x6
191 ; CHECK-NEXT: mov w0, w19
193 ; CHECK-NEXT: cbnz w19, .LBB9_2
194 ; CHECK-NEXT: // %bb.1: // %if.end
195 ; CHECK-NEXT: ldp x30, x19, [sp], #16 // 16-byte Folded Reload
197 ; CHECK-NEXT: .LBB9_2: // %if.then
201 call void @bar(i32 %c)
202 %tobool = icmp eq i32 %c, 0
203 br i1 %tobool, label %if.end, label %if.then
206 tail call void @foo()