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