1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs < %s | FileCheck %s
4 define i8 @test1(i32 %a) {
6 ; CHECK: // %bb.0: // %entry
7 ; CHECK-NEXT: and w8, w0, #0x3ffc00
8 ; CHECK-NEXT: and w8, w8, #0xffe007ff
9 ; CHECK-NEXT: cmp w8, #1024
10 ; CHECK-NEXT: cset w0, eq
13 %and = and i32 %a, 2098176
14 %cmp = icmp eq i32 %and, 1024
15 %conv = zext i1 %cmp to i8
19 ; This constant should not be split because it can be handled by one mov.
20 define i8 @test2(i32 %a) {
22 ; CHECK: // %bb.0: // %entry
23 ; CHECK-NEXT: mov w8, #135
24 ; CHECK-NEXT: and w8, w0, w8
25 ; CHECK-NEXT: cmp w8, #1024
26 ; CHECK-NEXT: cset w0, eq
29 %and = and i32 %a, 135
30 %cmp = icmp eq i32 %and, 1024
31 %conv = zext i1 %cmp to i8
35 ; This constant should not be split because the split immediate is not valid
37 define i8 @test3(i32 %a) {
39 ; CHECK: // %bb.0: // %entry
40 ; CHECK-NEXT: mov w8, #1024
41 ; CHECK-NEXT: movk w8, #33, lsl #16
42 ; CHECK-NEXT: and w8, w0, w8
43 ; CHECK-NEXT: cmp w8, #1024
44 ; CHECK-NEXT: cset w0, eq
47 %and = and i32 %a, 2163712
48 %cmp = icmp eq i32 %and, 1024
49 %conv = zext i1 %cmp to i8
53 define i8 @test4(i64 %a) {
55 ; CHECK: // %bb.0: // %entry
56 ; CHECK-NEXT: and x8, x0, #0x3ffc00
57 ; CHECK-NEXT: and x8, x8, #0xffffffffffe007ff
58 ; CHECK-NEXT: cmp x8, #1024
59 ; CHECK-NEXT: cset w0, eq
62 %and = and i64 %a, 2098176
63 %cmp = icmp eq i64 %and, 1024
64 %conv = zext i1 %cmp to i8
68 define i8 @test5(i64 %a) {
70 ; CHECK: // %bb.0: // %entry
71 ; CHECK-NEXT: and x8, x0, #0x3ffffc000
72 ; CHECK-NEXT: and x8, x8, #0xfffffffe00007fff
73 ; CHECK-NEXT: cmp x8, #1024
74 ; CHECK-NEXT: cset w0, eq
77 %and = and i64 %a, 8589950976
78 %cmp = icmp eq i64 %and, 1024
79 %conv = zext i1 %cmp to i8
83 ; This constant should not be split because it can be handled by one mov.
84 define i8 @test6(i64 %a) {
86 ; CHECK: // %bb.0: // %entry
87 ; CHECK-NEXT: mov w8, #135
88 ; CHECK-NEXT: and x8, x0, x8
89 ; CHECK-NEXT: cmp x8, #1024
90 ; CHECK-NEXT: cset w0, eq
93 %and = and i64 %a, 135
94 %cmp = icmp eq i64 %and, 1024
95 %conv = zext i1 %cmp to i8
99 ; This constant should not be split because the split immediate is not valid
101 define i8 @test7(i64 %a) {
102 ; CHECK-LABEL: test7:
103 ; CHECK: // %bb.0: // %entry
104 ; CHECK-NEXT: mov w8, #1024
105 ; CHECK-NEXT: movk w8, #33, lsl #16
106 ; CHECK-NEXT: and x8, x0, x8
107 ; CHECK-NEXT: cmp x8, #1024
108 ; CHECK-NEXT: cset w0, eq
111 %and = and i64 %a, 2163712
112 %cmp = icmp eq i64 %and, 1024
113 %conv = zext i1 %cmp to i8
117 ; The split bitmask immediates should be hoisted outside loop because they are
119 define void @test8(i64 %a, ptr noalias %src, ptr noalias %dst, i64 %n) {
120 ; CHECK-LABEL: test8:
121 ; CHECK: // %bb.0: // %loop.ph
122 ; CHECK-NEXT: and x9, x0, #0x3ffc00
123 ; CHECK-NEXT: mov x8, xzr
124 ; CHECK-NEXT: and x9, x9, #0xffffffffffe007ff
125 ; CHECK-NEXT: b .LBB7_2
126 ; CHECK-NEXT: .LBB7_1: // %for.inc
127 ; CHECK-NEXT: // in Loop: Header=BB7_2 Depth=1
128 ; CHECK-NEXT: add x8, x8, #1
129 ; CHECK-NEXT: cmp x8, x3
130 ; CHECK-NEXT: b.gt .LBB7_4
131 ; CHECK-NEXT: .LBB7_2: // %loop
132 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
133 ; CHECK-NEXT: cmp x8, x9
134 ; CHECK-NEXT: b.hs .LBB7_1
135 ; CHECK-NEXT: // %bb.3: // %if.then
136 ; CHECK-NEXT: // in Loop: Header=BB7_2 Depth=1
137 ; CHECK-NEXT: lsl x10, x8, #3
138 ; CHECK-NEXT: ldr x11, [x1, x10]
139 ; CHECK-NEXT: str x11, [x2, x10]
140 ; CHECK-NEXT: b .LBB7_1
141 ; CHECK-NEXT: .LBB7_4: // %exit
147 %iv = phi i64 [ %inc, %for.inc ], [ 0, %loop.ph ]
148 %and = and i64 %a, 2098176
149 %cmp = icmp ult i64 %iv, %and
150 br i1 %cmp, label %if.then, label %if.else
153 %src.arrayidx = getelementptr inbounds i64, ptr %src, i64 %iv
154 %val = load i64, ptr %src.arrayidx
155 %dst.arrayidx = getelementptr inbounds i64, ptr %dst, i64 %iv
156 store i64 %val, ptr %dst.arrayidx
163 %inc = add nuw nsw i64 %iv, 1
164 %cond = icmp sgt i64 %inc, %n
165 br i1 %cond, label %exit, label %loop
171 ; This constant should not be split because the `and` is not loop invariant.
172 define i32 @test9(ptr nocapture %x, ptr nocapture readonly %y, i32 %n) {
173 ; CHECK-LABEL: test9:
174 ; CHECK: // %bb.0: // %entry
175 ; CHECK-NEXT: cmp w2, #1
176 ; CHECK-NEXT: b.lt .LBB8_3
177 ; CHECK-NEXT: // %bb.1: // %for.body.preheader
178 ; CHECK-NEXT: mov w9, #1024
179 ; CHECK-NEXT: mov w8, w2
180 ; CHECK-NEXT: movk w9, #32, lsl #16
181 ; CHECK-NEXT: .LBB8_2: // %for.body
182 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
183 ; CHECK-NEXT: ldr w10, [x1], #4
184 ; CHECK-NEXT: subs x8, x8, #1
185 ; CHECK-NEXT: and w10, w10, w9
186 ; CHECK-NEXT: str w10, [x0], #4
187 ; CHECK-NEXT: b.ne .LBB8_2
188 ; CHECK-NEXT: .LBB8_3: // %for.cond.cleanup
189 ; CHECK-NEXT: mov w0, wzr
192 %cmp8 = icmp sgt i32 %n, 0
193 br i1 %cmp8, label %for.body.preheader, label %for.cond.cleanup
195 for.body.preheader: ; preds = %entry
196 %wide.trip.count = zext i32 %n to i64
199 for.cond.cleanup: ; preds = %for.body, %entry
202 for.body: ; preds = %for.body.preheader, %for.body
203 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
204 %arrayidx = getelementptr inbounds i32, ptr %y, i64 %indvars.iv
205 %0 = load i32, ptr %arrayidx, align 4
206 %and = and i32 %0, 2098176
207 %arrayidx2 = getelementptr inbounds i32, ptr %x, i64 %indvars.iv
208 store i32 %and, ptr %arrayidx2, align 4
209 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
210 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
211 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
214 ; After instruction selection end, we can see the `and` and `or` share the
217 ; %4:gpr32 = MOVi32imm 2098176
218 ; %5:gpr32 = ANDWrr killed %3:gpr32, %4:gpr32
219 ; STRWui killed %5:gpr32, %0:gpr64common, 0 :: (store (s32) into %ir.x, !tbaa !8)
220 ; %6:gpr32 = LDRWui %1:gpr64common, 0 :: (load (s32) from %ir.y, !tbaa !8)
221 ; %7:gpr32 = ORRWrr killed %6:gpr32, %4:gpr32
223 ; In this case, the constant should not be split because it causes more
225 define void @test10(ptr nocapture %x, ptr nocapture readonly %y, ptr nocapture %z) {
226 ; CHECK-LABEL: test10:
227 ; CHECK: // %bb.0: // %entry
228 ; CHECK-NEXT: ldr w8, [x1]
229 ; CHECK-NEXT: mov w9, #1024
230 ; CHECK-NEXT: movk w9, #32, lsl #16
231 ; CHECK-NEXT: and w8, w8, w9
232 ; CHECK-NEXT: str w8, [x0]
233 ; CHECK-NEXT: ldr w8, [x1]
234 ; CHECK-NEXT: orr w8, w8, w9
235 ; CHECK-NEXT: str w8, [x2]
238 %0 = load i32, ptr %y, align 4
239 %and = and i32 %0, 2098176
240 store i32 %and, ptr %x, align 4
241 %1 = load i32, ptr %y, align 4
242 %or = or i32 %1, 2098176
243 store i32 %or, ptr %z, align 4
247 ; This test genereates below MIs.
249 ; MOVi32imm -1610612736
252 ; The constant should be zero-extended to 64 bit and it should not be split.
253 define i8 @test11(i64 %a) {
254 ; CHECK-LABEL: test11:
255 ; CHECK: // %bb.0: // %entry
256 ; CHECK-NEXT: mov w8, #-1610612736
257 ; CHECK-NEXT: and x8, x0, x8
258 ; CHECK-NEXT: cmp x8, #1024
259 ; CHECK-NEXT: cset w0, eq
262 %and = and i64 %a, 2684354560
263 %cmp = icmp eq i64 %and, 1024
264 %conv = zext i1 %cmp to i8