1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=aarch64-- | FileCheck %s
; logic shift reg pattern: and
; already optimized by another pattern
define i64 @and_shiftedreg_from_and(i64 %a, i64 %b) {
; CHECK-LABEL: and_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: and x8, x1, x0, asr #23
; CHECK-NEXT: and x0, x8, #0xffffffffff000000
; CHECK-NEXT: ret
%ashr = ashr i64 %a, 23
%and = and i64 %ashr, -16777216
%r = and i64 %b, %and
ret i64 %r
}
; TODO: logic shift reg pattern: bic
define i64 @bic_shiftedreg_from_and(i64 %a, i64 %b) {
; CHECK-LABEL: bic_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: mov w8, #16777215 // =0xffffff
; CHECK-NEXT: orn x8, x8, x0, asr #23
; CHECK-NEXT: and x0, x1, x8
; CHECK-NEXT: ret
%ashr = ashr i64 %a, 23
%and = and i64 %ashr, -16777216
%not = xor i64 %and, -1
%r = and i64 %b, %not
ret i64 %r
}
; logic shift reg pattern: eon
define i64 @eon_shiftedreg_from_and(i64 %a, i64 %b) {
; CHECK-LABEL: eon_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: lsr x8, x0, #17
; CHECK-NEXT: eon x0, x1, x8, lsl #53
; CHECK-NEXT: ret
%shl = shl i64 %a, 36
%and = and i64 %shl, -9007199254740992
%xor = xor i64 %and, -1
%r = xor i64 %b, %xor
ret i64 %r
}
; logic shift reg pattern: eor
define i64 @eor_shiftedreg_from_and(i64 %a, i64 %b) {
; CHECK-LABEL: eor_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: lsr x8, x0, #47
; CHECK-NEXT: eor x0, x1, x8, lsl #24
; CHECK-NEXT: ret
%lshr = lshr i64 %a, 23
%and = and i64 %lshr, 2199006478336
%or = xor i64 %and, %b
ret i64 %or
}
; logic shift reg pattern: mvn
; already optimized by another pattern
define i64 @mvn_shiftedreg_from_and(i64 %a) {
; CHECK-LABEL: mvn_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: mov x8, #9007199254740991 // =0x1fffffffffffff
; CHECK-NEXT: orn x0, x8, x0, lsl #36
; CHECK-NEXT: ret
%shl = shl i64 %a, 36
%and = and i64 %shl, -9007199254740992
%xor = xor i64 %and, -1
ret i64 %xor
}
; logic shift reg pattern: orn
; already optimized by another pattern
define i64 @orn_shiftedreg_from_and(i64 %a, i64 %b) {
; CHECK-LABEL: orn_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: orn x8, x1, x0, lsr #23
; CHECK-NEXT: orr x0, x8, #0xfffffe0000ffffff
; CHECK-NEXT: ret
%lshr = lshr i64 %a, 23
%and = and i64 %lshr, 2199006478336
%not = xor i64 %and, -1
%or = or i64 %not, %b
ret i64 %or
}
; logic shift reg pattern: orr
; srl constant bitwidth == (lowbits + masklen + shiftamt)
define i64 @orr_shiftedreg_from_and(i64 %a, i64 %b) {
; CHECK-LABEL: orr_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: lsr x8, x0, #47
; CHECK-NEXT: orr x0, x1, x8, lsl #24
; CHECK-NEXT: ret
%lshr = lshr i64 %a, 23
%and = and i64 %lshr, 2199006478336 ; 0x1ffff000000
%or = or i64 %and, %b
ret i64 %or
}
; logic shift reg pattern: orr
; srl constant bitwidth < (lowbits + masklen + shiftamt)
define i64 @orr_shiftedreg_from_and_mask2(i64 %a, i64 %b) {
; CHECK-LABEL: orr_shiftedreg_from_and_mask2:
; CHECK: // %bb.0:
; CHECK-NEXT: lsr x8, x0, #47
; CHECK-NEXT: orr x0, x1, x8, lsl #24
; CHECK-NEXT: ret
%lshr = lshr i64 %a, 23
%and = and i64 %lshr, 4398029733888 ; 0x3ffff000000
%or = or i64 %and, %b
ret i64 %or
}
; arithmetic shift reg pattern: add
define i32 @add_shiftedreg_from_and(i32 %a, i32 %b) {
; CHECK-LABEL: add_shiftedreg_from_and:
; CHECK: // %bb.0:
; CHECK-NEXT: asr w8, w0, #27
; CHECK-NEXT: add w0, w1, w8, lsl #24
; CHECK-NEXT: ret
%ashr = ashr i32 %a, 3
%and = and i32 %ashr, -16777216
%add = add i32 %and, %b
ret i32 %add
}
; arithmetic shift reg pattern: sub
define i64 @sub_shiftedreg_from_and_shl(i64 %a, i64 %b) {
; CHECK-LABEL: sub_shiftedreg_from_and_shl:
; CHECK: // %bb.0:
; CHECK-NEXT: lsr x8, x0, #17
; CHECK-NEXT: sub x0, x1, x8, lsl #53
; CHECK-NEXT: ret
%shl = shl i64 %a, 36
%and = and i64 %shl, -9007199254740992
%sub = sub i64 %b, %and
ret i64 %sub
}
; negative test: type is not i32 or i64
define <2 x i32> @shiftedreg_from_and_negative_type(<2 x i32> %a, <2 x i32> %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_type:
; CHECK: // %bb.0:
; CHECK-NEXT: shl v0.2s, v0.2s, #2
; CHECK-NEXT: bic v0.2s, #28
; CHECK-NEXT: sub v0.2s, v1.2s, v0.2s
; CHECK-NEXT: ret
%shl = shl <2 x i32> %a, <i32 2, i32 2>
%and = and <2 x i32> %shl, <i32 -32, i32 -32>
%sub = sub <2 x i32> %b, %and
ret <2 x i32> %sub
}
; negative test: shift one-use
define i32 @shiftedreg_from_and_negative_oneuse1(i32 %a, i32 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_oneuse1:
; CHECK: // %bb.0:
; CHECK-NEXT: asr w8, w0, #23
; CHECK-NEXT: and w9, w8, #0xff000000
; CHECK-NEXT: add w9, w9, w1
; CHECK-NEXT: mul w0, w8, w9
; CHECK-NEXT: ret
%ashr = ashr i32 %a, 23
%and = and i32 %ashr, -16777216
%add = add i32 %and, %b
%r = mul i32 %ashr, %add
ret i32 %r
}
; negative test: and one-use
define i32 @shiftedreg_from_and_negative_oneuse2(i32 %a, i32 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_oneuse2:
; CHECK: // %bb.0:
; CHECK-NEXT: asr w8, w0, #23
; CHECK-NEXT: and w8, w8, #0xff000000
; CHECK-NEXT: add w9, w8, w1
; CHECK-NEXT: mul w0, w8, w9
; CHECK-NEXT: ret
%ashr = ashr i32 %a, 23
%and = and i32 %ashr, -16777216
%add = add i32 %and, %b
%r = mul i32 %and, %add
ret i32 %r
}
; negative test: and c is not mask
define i32 @shiftedreg_from_and_negative_andc1(i32 %a, i32 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_andc1:
; CHECK: // %bb.0:
; CHECK-NEXT: mov w8, #26215 // =0x6667
; CHECK-NEXT: movk w8, #65510, lsl #16
; CHECK-NEXT: and w8, w8, w0, asr #23
; CHECK-NEXT: add w0, w8, w1
; CHECK-NEXT: ret
%ashr = ashr i32 %a, 23
%and = and i32 %ashr, -1677721
%add = add i32 %and, %b
ret i32 %add
}
; negative test: sra with and c is not legal mask
define i32 @shiftedreg_from_and_negative_andc2(i32 %a, i32 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_andc2:
; CHECK: // %bb.0:
; CHECK-NEXT: mov w8, #-285212672 // =0xef000000
; CHECK-NEXT: and w8, w8, w0, asr #23
; CHECK-NEXT: add w0, w8, w1
; CHECK-NEXT: ret
%ashr = ashr i32 %a, 23
%and = and i32 %ashr, 4009754624 ; 0xef000000
%add = add i32 %and, %b
ret i32 %add
}
; negative test: shl with and c is not legal mask
define i64 @shiftedreg_from_and_negative_andc3(i64 %a, i64 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_andc3:
; CHECK: // %bb.0:
; CHECK-NEXT: eor x0, x1, x0, lsl #36
; CHECK-NEXT: ret
%shl = shl i64 %a, 36
%and = and i64 %shl, -4294967296
%xor = xor i64 %and, %b
ret i64 %xor
}
; negative test: shl with and c is not legal mask
define i64 @shiftedreg_from_and_negative_andc4(i64 %a, i64 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_andc4:
; CHECK: // %bb.0:
; CHECK-NEXT: lsl x8, x0, #36
; CHECK-NEXT: and x8, x8, #0x7fe0000000000000
; CHECK-NEXT: eor x0, x8, x1
; CHECK-NEXT: ret
%shl = shl i64 %a, 36
%and = and i64 %shl, 9214364837600034816
%xor = xor i64 %and, %b
ret i64 %xor
}
; negative test: sra with and c is not legal mask
define i32 @shiftedreg_from_and_negative_andc5(i32 %a, i32 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_andc5:
; CHECK: // %bb.0:
; CHECK-NEXT: asr w8, w0, #23
; CHECK-NEXT: and w8, w8, #0xff000000
; CHECK-NEXT: add w0, w8, w1
; CHECK-NEXT: ret
%ashr = ashr i32 %a, 23
%and = and i32 %ashr, -16777216
%add = add i32 %and, %b
ret i32 %add
}
; negative test: srl with and c is not legal mask
; srl constant bitwidth > (lowbits + masklen + shiftamt)
define i64 @shiftedreg_from_and_negative_andc6(i64 %a, i64 %b) {
; CHECK-LABEL: shiftedreg_from_and_negative_andc6:
; CHECK: // %bb.0:
; CHECK-NEXT: lsr x8, x0, #2
; CHECK-NEXT: and x8, x8, #0x6
; CHECK-NEXT: add x0, x8, x1
; CHECK-NEXT: ret
%lshr = lshr i64 %a, 2
%and = and i64 %lshr, 6
%add = add i64 %and, %b
ret i64 %add
}
|