|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | +; RUN: llc -mtriple=riscv32 -mattr=+zbb -verify-machineinstrs < %s \ |
| 3 | +; RUN: | FileCheck %s --check-prefixes=CHECK,RV32,NOZBS32 |
| 4 | +; RUN: llc -mtriple=riscv64 -mattr=+zbb -verify-machineinstrs < %s \ |
| 5 | +; RUN: | FileCheck %s --check-prefixes=CHECK,RV64,NOZBS64 |
| 6 | +; RUN: llc -mtriple=riscv32 -mattr=+zbb,+zbs -verify-machineinstrs < %s \ |
| 7 | +; RUN: | FileCheck %s --check-prefixes=CHECK,RV32,ZBS |
| 8 | +; RUN: llc -mtriple=riscv64 -mattr=+zbb,+zbs -verify-machineinstrs < %s \ |
| 9 | +; RUN: | FileCheck %s --check-prefixes=CHECK,RV64,ZBS |
| 10 | + |
| 11 | +define i32 @and0xabcdefff(i32 %x) { |
| 12 | +; RV32-LABEL: and0xabcdefff: |
| 13 | +; RV32: # %bb.0: |
| 14 | +; RV32-NEXT: lui a1, 703711 |
| 15 | +; RV32-NEXT: addi a1, a1, -1 |
| 16 | +; RV32-NEXT: and a0, a0, a1 |
| 17 | +; RV32-NEXT: ret |
| 18 | +; |
| 19 | +; RV64-LABEL: and0xabcdefff: |
| 20 | +; RV64: # %bb.0: |
| 21 | +; RV64-NEXT: lui a1, 703711 |
| 22 | +; RV64-NEXT: addiw a1, a1, -1 |
| 23 | +; RV64-NEXT: and a0, a0, a1 |
| 24 | +; RV64-NEXT: ret |
| 25 | + %and = and i32 %x, -1412567041 |
| 26 | + ret i32 %and |
| 27 | +} |
| 28 | + |
| 29 | +define i32 @orlow13(i32 %x) { |
| 30 | +; RV32-LABEL: orlow13: |
| 31 | +; RV32: # %bb.0: |
| 32 | +; RV32-NEXT: lui a1, 2 |
| 33 | +; RV32-NEXT: addi a1, a1, -1 |
| 34 | +; RV32-NEXT: or a0, a0, a1 |
| 35 | +; RV32-NEXT: ret |
| 36 | +; |
| 37 | +; RV64-LABEL: orlow13: |
| 38 | +; RV64: # %bb.0: |
| 39 | +; RV64-NEXT: lui a1, 2 |
| 40 | +; RV64-NEXT: addiw a1, a1, -1 |
| 41 | +; RV64-NEXT: or a0, a0, a1 |
| 42 | +; RV64-NEXT: ret |
| 43 | + %or = or i32 %x, 8191 |
| 44 | + ret i32 %or |
| 45 | +} |
| 46 | + |
| 47 | +define i64 @orlow24(i64 %x) { |
| 48 | +; RV32-LABEL: orlow24: |
| 49 | +; RV32: # %bb.0: |
| 50 | +; RV32-NEXT: lui a2, 4096 |
| 51 | +; RV32-NEXT: addi a2, a2, -1 |
| 52 | +; RV32-NEXT: or a0, a0, a2 |
| 53 | +; RV32-NEXT: ret |
| 54 | +; |
| 55 | +; RV64-LABEL: orlow24: |
| 56 | +; RV64: # %bb.0: |
| 57 | +; RV64-NEXT: lui a1, 4096 |
| 58 | +; RV64-NEXT: addiw a1, a1, -1 |
| 59 | +; RV64-NEXT: or a0, a0, a1 |
| 60 | +; RV64-NEXT: ret |
| 61 | + %or = or i64 %x, 16777215 |
| 62 | + ret i64 %or |
| 63 | +} |
| 64 | + |
| 65 | +define i32 @xorlow16(i32 %x) { |
| 66 | +; RV32-LABEL: xorlow16: |
| 67 | +; RV32: # %bb.0: |
| 68 | +; RV32-NEXT: lui a1, 16 |
| 69 | +; RV32-NEXT: addi a1, a1, -1 |
| 70 | +; RV32-NEXT: xor a0, a0, a1 |
| 71 | +; RV32-NEXT: ret |
| 72 | +; |
| 73 | +; RV64-LABEL: xorlow16: |
| 74 | +; RV64: # %bb.0: |
| 75 | +; RV64-NEXT: lui a1, 16 |
| 76 | +; RV64-NEXT: addiw a1, a1, -1 |
| 77 | +; RV64-NEXT: xor a0, a0, a1 |
| 78 | +; RV64-NEXT: ret |
| 79 | + %xor = xor i32 %x, 65535 |
| 80 | + ret i32 %xor |
| 81 | +} |
| 82 | + |
| 83 | +define i32 @xorlow31(i32 %x) { |
| 84 | +; RV32-LABEL: xorlow31: |
| 85 | +; RV32: # %bb.0: |
| 86 | +; RV32-NEXT: lui a1, 524288 |
| 87 | +; RV32-NEXT: addi a1, a1, -1 |
| 88 | +; RV32-NEXT: xor a0, a0, a1 |
| 89 | +; RV32-NEXT: ret |
| 90 | +; |
| 91 | +; RV64-LABEL: xorlow31: |
| 92 | +; RV64: # %bb.0: |
| 93 | +; RV64-NEXT: lui a1, 524288 |
| 94 | +; RV64-NEXT: addiw a1, a1, -1 |
| 95 | +; RV64-NEXT: xor a0, a0, a1 |
| 96 | +; RV64-NEXT: ret |
| 97 | + %xor = xor i32 %x, 2147483647 |
| 98 | + ret i32 %xor |
| 99 | +} |
| 100 | + |
| 101 | +define i32 @oraddlow16(i32 %x) { |
| 102 | +; RV32-LABEL: oraddlow16: |
| 103 | +; RV32: # %bb.0: |
| 104 | +; RV32-NEXT: lui a1, 16 |
| 105 | +; RV32-NEXT: addi a1, a1, -1 |
| 106 | +; RV32-NEXT: or a0, a0, a1 |
| 107 | +; RV32-NEXT: add a0, a0, a1 |
| 108 | +; RV32-NEXT: ret |
| 109 | +; |
| 110 | +; RV64-LABEL: oraddlow16: |
| 111 | +; RV64: # %bb.0: |
| 112 | +; RV64-NEXT: lui a1, 16 |
| 113 | +; RV64-NEXT: addi a1, a1, -1 |
| 114 | +; RV64-NEXT: or a0, a0, a1 |
| 115 | +; RV64-NEXT: addw a0, a0, a1 |
| 116 | +; RV64-NEXT: ret |
| 117 | + %or = or i32 %x, 65535 |
| 118 | + %add = add nsw i32 %or, 65535 |
| 119 | + ret i32 %add |
| 120 | +} |
| 121 | + |
| 122 | +define i32 @addorlow16(i32 %x) { |
| 123 | +; RV32-LABEL: addorlow16: |
| 124 | +; RV32: # %bb.0: |
| 125 | +; RV32-NEXT: lui a1, 16 |
| 126 | +; RV32-NEXT: addi a1, a1, -1 |
| 127 | +; RV32-NEXT: add a0, a0, a1 |
| 128 | +; RV32-NEXT: or a0, a0, a1 |
| 129 | +; RV32-NEXT: ret |
| 130 | +; |
| 131 | +; RV64-LABEL: addorlow16: |
| 132 | +; RV64: # %bb.0: |
| 133 | +; RV64-NEXT: lui a1, 16 |
| 134 | +; RV64-NEXT: addiw a1, a1, -1 |
| 135 | +; RV64-NEXT: addw a0, a0, a1 |
| 136 | +; RV64-NEXT: or a0, a0, a1 |
| 137 | +; RV64-NEXT: ret |
| 138 | + %add = add nsw i32 %x, 65535 |
| 139 | + %or = or i32 %add, 65535 |
| 140 | + ret i32 %or |
| 141 | +} |
| 142 | + |
| 143 | +define i32 @andxorlow16(i32 %x) { |
| 144 | +; RV32-LABEL: andxorlow16: |
| 145 | +; RV32: # %bb.0: |
| 146 | +; RV32-NEXT: lui a1, 16 |
| 147 | +; RV32-NEXT: addi a1, a1, -1 |
| 148 | +; RV32-NEXT: andn a0, a1, a0 |
| 149 | +; RV32-NEXT: ret |
| 150 | +; |
| 151 | +; RV64-LABEL: andxorlow16: |
| 152 | +; RV64: # %bb.0: |
| 153 | +; RV64-NEXT: lui a1, 16 |
| 154 | +; RV64-NEXT: addiw a1, a1, -1 |
| 155 | +; RV64-NEXT: andn a0, a1, a0 |
| 156 | +; RV64-NEXT: ret |
| 157 | + %and = and i32 %x, 65535 |
| 158 | + %xor = xor i32 %and, 65535 |
| 159 | + ret i32 %xor |
| 160 | +} |
| 161 | + |
| 162 | +define void @orarray100(ptr %a) { |
| 163 | +; RV32-LABEL: orarray100: |
| 164 | +; RV32: # %bb.0: # %entry |
| 165 | +; RV32-NEXT: li a1, 0 |
| 166 | +; RV32-NEXT: li a2, 0 |
| 167 | +; RV32-NEXT: lui a3, 16 |
| 168 | +; RV32-NEXT: addi a3, a3, -1 |
| 169 | +; RV32-NEXT: .LBB8_1: # %for.body |
| 170 | +; RV32-NEXT: # =>This Inner Loop Header: Depth=1 |
| 171 | +; RV32-NEXT: slli a4, a1, 2 |
| 172 | +; RV32-NEXT: addi a1, a1, 1 |
| 173 | +; RV32-NEXT: add a4, a0, a4 |
| 174 | +; RV32-NEXT: lw a5, 0(a4) |
| 175 | +; RV32-NEXT: seqz a6, a1 |
| 176 | +; RV32-NEXT: add a2, a2, a6 |
| 177 | +; RV32-NEXT: xori a6, a1, 100 |
| 178 | +; RV32-NEXT: or a5, a5, a3 |
| 179 | +; RV32-NEXT: or a6, a6, a2 |
| 180 | +; RV32-NEXT: sw a5, 0(a4) |
| 181 | +; RV32-NEXT: bnez a6, .LBB8_1 |
| 182 | +; RV32-NEXT: # %bb.2: # %for.cond.cleanup |
| 183 | +; RV32-NEXT: ret |
| 184 | +; |
| 185 | +; RV64-LABEL: orarray100: |
| 186 | +; RV64: # %bb.0: # %entry |
| 187 | +; RV64-NEXT: addi a1, a0, 400 |
| 188 | +; RV64-NEXT: lui a2, 16 |
| 189 | +; RV64-NEXT: addi a2, a2, -1 |
| 190 | +; RV64-NEXT: .LBB8_1: # %for.body |
| 191 | +; RV64-NEXT: # =>This Inner Loop Header: Depth=1 |
| 192 | +; RV64-NEXT: lw a3, 0(a0) |
| 193 | +; RV64-NEXT: or a3, a3, a2 |
| 194 | +; RV64-NEXT: sw a3, 0(a0) |
| 195 | +; RV64-NEXT: addi a0, a0, 4 |
| 196 | +; RV64-NEXT: bne a0, a1, .LBB8_1 |
| 197 | +; RV64-NEXT: # %bb.2: # %for.cond.cleanup |
| 198 | +; RV64-NEXT: ret |
| 199 | +entry: |
| 200 | + br label %for.body |
| 201 | + |
| 202 | +for.cond.cleanup: |
| 203 | + ret void |
| 204 | + |
| 205 | +for.body: |
| 206 | + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] |
| 207 | + %arrayidx = getelementptr inbounds nuw i32, ptr %a, i64 %indvars.iv |
| 208 | + %1 = load i32, ptr %arrayidx, align 4 |
| 209 | + %or = or i32 %1, 65535 |
| 210 | + store i32 %or, ptr %arrayidx, align 4 |
| 211 | + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 212 | + %exitcond.not = icmp eq i64 %indvars.iv.next, 100 |
| 213 | + br i1 %exitcond.not, label %for.cond.cleanup, label %for.body |
| 214 | +} |
| 215 | + |
| 216 | +define void @orarray3(ptr %a) { |
| 217 | +; CHECK-LABEL: orarray3: |
| 218 | +; CHECK: # %bb.0: |
| 219 | +; CHECK-NEXT: lui a1, 16 |
| 220 | +; CHECK-NEXT: lw a2, 0(a0) |
| 221 | +; CHECK-NEXT: lw a3, 4(a0) |
| 222 | +; CHECK-NEXT: lw a4, 8(a0) |
| 223 | +; CHECK-NEXT: addi a1, a1, -1 |
| 224 | +; CHECK-NEXT: or a2, a2, a1 |
| 225 | +; CHECK-NEXT: or a3, a3, a1 |
| 226 | +; CHECK-NEXT: or a1, a4, a1 |
| 227 | +; CHECK-NEXT: sw a2, 0(a0) |
| 228 | +; CHECK-NEXT: sw a3, 4(a0) |
| 229 | +; CHECK-NEXT: sw a1, 8(a0) |
| 230 | +; CHECK-NEXT: ret |
| 231 | + %1 = load i32, ptr %a, align 4 |
| 232 | + %or = or i32 %1, 65535 |
| 233 | + store i32 %or, ptr %a, align 4 |
| 234 | + %arrayidx.1 = getelementptr inbounds nuw i8, ptr %a, i64 4 |
| 235 | + %2 = load i32, ptr %arrayidx.1, align 4 |
| 236 | + %or.1 = or i32 %2, 65535 |
| 237 | + store i32 %or.1, ptr %arrayidx.1, align 4 |
| 238 | + %arrayidx.2 = getelementptr inbounds nuw i8, ptr %a, i64 8 |
| 239 | + %3 = load i32, ptr %arrayidx.2, align 4 |
| 240 | + %or.2 = or i32 %3, 65535 |
| 241 | + store i32 %or.2, ptr %arrayidx.2, align 4 |
| 242 | + ret void |
| 243 | +} |
| 244 | + |
| 245 | +define i32 @andlow16(i32 %x) { |
| 246 | +; CHECK-LABEL: andlow16: |
| 247 | +; CHECK: # %bb.0: |
| 248 | +; CHECK-NEXT: zext.h a0, a0 |
| 249 | +; CHECK-NEXT: ret |
| 250 | + %and = and i32 %x, 65535 |
| 251 | + ret i32 %and |
| 252 | +} |
| 253 | + |
| 254 | +define i32 @andlow24(i32 %x) { |
| 255 | +; RV32-LABEL: andlow24: |
| 256 | +; RV32: # %bb.0: |
| 257 | +; RV32-NEXT: slli a0, a0, 8 |
| 258 | +; RV32-NEXT: srli a0, a0, 8 |
| 259 | +; RV32-NEXT: ret |
| 260 | +; |
| 261 | +; RV64-LABEL: andlow24: |
| 262 | +; RV64: # %bb.0: |
| 263 | +; RV64-NEXT: slli a0, a0, 40 |
| 264 | +; RV64-NEXT: srli a0, a0, 40 |
| 265 | +; RV64-NEXT: ret |
| 266 | + %and = and i32 %x, 16777215 |
| 267 | + ret i32 %and |
| 268 | +} |
| 269 | + |
| 270 | +define i32 @compl(i32 %x) { |
| 271 | +; CHECK-LABEL: compl: |
| 272 | +; CHECK: # %bb.0: |
| 273 | +; CHECK-NEXT: not a0, a0 |
| 274 | +; CHECK-NEXT: ret |
| 275 | + %not = xor i32 %x, -1 |
| 276 | + ret i32 %not |
| 277 | +} |
| 278 | + |
| 279 | +define i32 @orlow12(i32 %x) { |
| 280 | +; NOZBS32-LABEL: orlow12: |
| 281 | +; NOZBS32: # %bb.0: |
| 282 | +; NOZBS32-NEXT: lui a1, 1 |
| 283 | +; NOZBS32-NEXT: addi a1, a1, -1 |
| 284 | +; NOZBS32-NEXT: or a0, a0, a1 |
| 285 | +; NOZBS32-NEXT: ret |
| 286 | +; |
| 287 | +; NOZBS64-LABEL: orlow12: |
| 288 | +; NOZBS64: # %bb.0: |
| 289 | +; NOZBS64-NEXT: lui a1, 1 |
| 290 | +; NOZBS64-NEXT: addiw a1, a1, -1 |
| 291 | +; NOZBS64-NEXT: or a0, a0, a1 |
| 292 | +; NOZBS64-NEXT: ret |
| 293 | +; |
| 294 | +; ZBS-LABEL: orlow12: |
| 295 | +; ZBS: # %bb.0: |
| 296 | +; ZBS-NEXT: ori a0, a0, 2047 |
| 297 | +; ZBS-NEXT: bseti a0, a0, 11 |
| 298 | +; ZBS-NEXT: ret |
| 299 | + %or = or i32 %x, 4095 |
| 300 | + ret i32 %or |
| 301 | +} |
| 302 | + |
| 303 | +define i32 @xorlow12(i32 %x) { |
| 304 | +; NOZBS32-LABEL: xorlow12: |
| 305 | +; NOZBS32: # %bb.0: |
| 306 | +; NOZBS32-NEXT: lui a1, 1 |
| 307 | +; NOZBS32-NEXT: addi a1, a1, -1 |
| 308 | +; NOZBS32-NEXT: xor a0, a0, a1 |
| 309 | +; NOZBS32-NEXT: ret |
| 310 | +; |
| 311 | +; NOZBS64-LABEL: xorlow12: |
| 312 | +; NOZBS64: # %bb.0: |
| 313 | +; NOZBS64-NEXT: lui a1, 1 |
| 314 | +; NOZBS64-NEXT: addiw a1, a1, -1 |
| 315 | +; NOZBS64-NEXT: xor a0, a0, a1 |
| 316 | +; NOZBS64-NEXT: ret |
| 317 | +; |
| 318 | +; ZBS-LABEL: xorlow12: |
| 319 | +; ZBS: # %bb.0: |
| 320 | +; ZBS-NEXT: xori a0, a0, 2047 |
| 321 | +; ZBS-NEXT: binvi a0, a0, 11 |
| 322 | +; ZBS-NEXT: ret |
| 323 | + %xor = xor i32 %x, 4095 |
| 324 | + ret i32 %xor |
| 325 | +} |
| 326 | + |
| 327 | +define i64 @andimm64(i64 %x) { |
| 328 | +; RV32-LABEL: andimm64: |
| 329 | +; RV32: # %bb.0: |
| 330 | +; RV32-NEXT: lui a1, 1044496 |
| 331 | +; RV32-NEXT: addi a1, a1, -1 |
| 332 | +; RV32-NEXT: and a0, a0, a1 |
| 333 | +; RV32-NEXT: li a1, 0 |
| 334 | +; RV32-NEXT: ret |
| 335 | +; |
| 336 | +; RV64-LABEL: andimm64: |
| 337 | +; RV64: # %bb.0: |
| 338 | +; RV64-NEXT: lui a1, 65281 |
| 339 | +; RV64-NEXT: slli a1, a1, 4 |
| 340 | +; RV64-NEXT: addi a1, a1, -1 |
| 341 | +; RV64-NEXT: and a0, a0, a1 |
| 342 | +; RV64-NEXT: ret |
| 343 | + %and = and i64 %x, 4278255615 |
| 344 | + ret i64 %and |
| 345 | +} |
| 346 | + |
| 347 | +define i64 @andimm64srli(i64 %x) { |
| 348 | +; RV32-LABEL: andimm64srli: |
| 349 | +; RV32: # %bb.0: |
| 350 | +; RV32-NEXT: lui a2, 917504 |
| 351 | +; RV32-NEXT: or a1, a1, a2 |
| 352 | +; RV32-NEXT: lui a2, 8192 |
| 353 | +; RV32-NEXT: addi a2, a2, -1 |
| 354 | +; RV32-NEXT: or a0, a0, a2 |
| 355 | +; RV32-NEXT: ret |
| 356 | +; |
| 357 | +; RV64-LABEL: andimm64srli: |
| 358 | +; RV64: # %bb.0: |
| 359 | +; RV64-NEXT: lui a1, 983040 |
| 360 | +; RV64-NEXT: srli a1, a1, 3 |
| 361 | +; RV64-NEXT: not a1, a1 |
| 362 | +; RV64-NEXT: or a0, a0, a1 |
| 363 | +; RV64-NEXT: ret |
| 364 | + %or = or i64 %x, -2305843009180139521 |
| 365 | + ret i64 %or |
| 366 | +} |
0 commit comments