|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | +; RUN: llc -mtriple=riscv32 < %s \ |
| 3 | +; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-I,RV32,RV32I |
| 4 | +; RUN: llc -mtriple=riscv64 < %s \ |
| 5 | +; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-I,RV64,RV64I |
| 6 | +; RUN: llc -mtriple=riscv32 -mattr=+zbb < %s \ |
| 7 | +; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-ZBB,RV32,RV32ZBB |
| 8 | +; RUN: llc -mtriple=riscv64 -mattr=+zbb < %s \ |
| 9 | +; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-ZBB,RV64,RV64ZBB |
| 10 | +; |
| 11 | +; test that masked-merge code is generated as "xor;and;xor" sequence or |
| 12 | +; "andn ; and; or" if and-not is available. |
| 13 | + |
| 14 | +define i32 @masked_merge0(i32 %a0, i32 %a1, i32 %a2) { |
| 15 | +; CHECK-I-LABEL: masked_merge0: |
| 16 | +; CHECK-I: # %bb.0: |
| 17 | +; CHECK-I-NEXT: and a1, a0, a1 |
| 18 | +; CHECK-I-NEXT: not a0, a0 |
| 19 | +; CHECK-I-NEXT: and a0, a0, a2 |
| 20 | +; CHECK-I-NEXT: or a0, a1, a0 |
| 21 | +; CHECK-I-NEXT: ret |
| 22 | +; |
| 23 | +; CHECK-ZBB-LABEL: masked_merge0: |
| 24 | +; CHECK-ZBB: # %bb.0: |
| 25 | +; CHECK-ZBB-NEXT: and a1, a0, a1 |
| 26 | +; CHECK-ZBB-NEXT: andn a0, a2, a0 |
| 27 | +; CHECK-ZBB-NEXT: or a0, a1, a0 |
| 28 | +; CHECK-ZBB-NEXT: ret |
| 29 | + %and0 = and i32 %a0, %a1 |
| 30 | + %not = xor i32 %a0, -1 |
| 31 | + %and1 = and i32 %not, %a2 |
| 32 | + %or = or i32 %and0, %and1 |
| 33 | + ret i32 %or |
| 34 | +} |
| 35 | + |
| 36 | +define i16 @masked_merge1(i16 %a0, i16 %a1, i16 %a2) { |
| 37 | +; CHECK-I-LABEL: masked_merge1: |
| 38 | +; CHECK-I: # %bb.0: |
| 39 | +; CHECK-I-NEXT: and a1, a0, a1 |
| 40 | +; CHECK-I-NEXT: not a0, a0 |
| 41 | +; CHECK-I-NEXT: and a0, a2, a0 |
| 42 | +; CHECK-I-NEXT: or a0, a1, a0 |
| 43 | +; CHECK-I-NEXT: ret |
| 44 | +; |
| 45 | +; CHECK-ZBB-LABEL: masked_merge1: |
| 46 | +; CHECK-ZBB: # %bb.0: |
| 47 | +; CHECK-ZBB-NEXT: and a1, a0, a1 |
| 48 | +; CHECK-ZBB-NEXT: andn a0, a2, a0 |
| 49 | +; CHECK-ZBB-NEXT: or a0, a1, a0 |
| 50 | +; CHECK-ZBB-NEXT: ret |
| 51 | + %and0 = and i16 %a0, %a1 |
| 52 | + %not = xor i16 %a0, -1 |
| 53 | + %and1 = and i16 %a2, %not |
| 54 | + %or = or i16 %and0, %and1 |
| 55 | + ret i16 %or |
| 56 | +} |
| 57 | + |
| 58 | +define i8 @masked_merge2(i8 %a0, i8 %a1, i8 %a2) { |
| 59 | +; CHECK-I-LABEL: masked_merge2: |
| 60 | +; CHECK-I: # %bb.0: |
| 61 | +; CHECK-I-NEXT: not a2, a0 |
| 62 | +; CHECK-I-NEXT: and a2, a2, a1 |
| 63 | +; CHECK-I-NEXT: and a0, a1, a0 |
| 64 | +; CHECK-I-NEXT: or a0, a2, a0 |
| 65 | +; CHECK-I-NEXT: ret |
| 66 | +; |
| 67 | +; CHECK-ZBB-LABEL: masked_merge2: |
| 68 | +; CHECK-ZBB: # %bb.0: |
| 69 | +; CHECK-ZBB-NEXT: andn a2, a1, a0 |
| 70 | +; CHECK-ZBB-NEXT: and a0, a1, a0 |
| 71 | +; CHECK-ZBB-NEXT: or a0, a2, a0 |
| 72 | +; CHECK-ZBB-NEXT: ret |
| 73 | + %not = xor i8 %a0, -1 |
| 74 | + %and0 = and i8 %not, %a1 |
| 75 | + %and1 = and i8 %a1, %a0 |
| 76 | + %or = or i8 %and0, %and1 |
| 77 | + ret i8 %or |
| 78 | +} |
| 79 | + |
| 80 | +define i64 @masked_merge3(i64 %a0, i64 %a1, i64 %a2) { |
| 81 | +; RV32I-LABEL: masked_merge3: |
| 82 | +; RV32I: # %bb.0: |
| 83 | +; RV32I-NEXT: not a2, a2 |
| 84 | +; RV32I-NEXT: not a3, a3 |
| 85 | +; RV32I-NEXT: not a4, a4 |
| 86 | +; RV32I-NEXT: not a5, a5 |
| 87 | +; RV32I-NEXT: not a6, a0 |
| 88 | +; RV32I-NEXT: not a7, a1 |
| 89 | +; RV32I-NEXT: and a5, a7, a5 |
| 90 | +; RV32I-NEXT: and a4, a6, a4 |
| 91 | +; RV32I-NEXT: and a1, a3, a1 |
| 92 | +; RV32I-NEXT: and a0, a2, a0 |
| 93 | +; RV32I-NEXT: or a0, a4, a0 |
| 94 | +; RV32I-NEXT: or a1, a5, a1 |
| 95 | +; RV32I-NEXT: ret |
| 96 | +; |
| 97 | +; RV64I-LABEL: masked_merge3: |
| 98 | +; RV64I: # %bb.0: |
| 99 | +; RV64I-NEXT: not a1, a1 |
| 100 | +; RV64I-NEXT: not a2, a2 |
| 101 | +; RV64I-NEXT: not a3, a0 |
| 102 | +; RV64I-NEXT: and a2, a3, a2 |
| 103 | +; RV64I-NEXT: and a0, a1, a0 |
| 104 | +; RV64I-NEXT: or a0, a2, a0 |
| 105 | +; RV64I-NEXT: ret |
| 106 | +; |
| 107 | +; RV32ZBB-LABEL: masked_merge3: |
| 108 | +; RV32ZBB: # %bb.0: |
| 109 | +; RV32ZBB-NEXT: not a6, a0 |
| 110 | +; RV32ZBB-NEXT: not a7, a1 |
| 111 | +; RV32ZBB-NEXT: andn a1, a1, a3 |
| 112 | +; RV32ZBB-NEXT: andn a0, a0, a2 |
| 113 | +; RV32ZBB-NEXT: andn a2, a7, a5 |
| 114 | +; RV32ZBB-NEXT: andn a3, a6, a4 |
| 115 | +; RV32ZBB-NEXT: or a0, a3, a0 |
| 116 | +; RV32ZBB-NEXT: or a1, a2, a1 |
| 117 | +; RV32ZBB-NEXT: ret |
| 118 | +; |
| 119 | +; RV64ZBB-LABEL: masked_merge3: |
| 120 | +; RV64ZBB: # %bb.0: |
| 121 | +; RV64ZBB-NEXT: not a3, a0 |
| 122 | +; RV64ZBB-NEXT: andn a2, a3, a2 |
| 123 | +; RV64ZBB-NEXT: andn a0, a0, a1 |
| 124 | +; RV64ZBB-NEXT: or a0, a2, a0 |
| 125 | +; RV64ZBB-NEXT: ret |
| 126 | + %v0 = xor i64 %a1, -1 |
| 127 | + %v1 = xor i64 %a2, -1 |
| 128 | + %not = xor i64 %a0, -1 |
| 129 | + %and0 = and i64 %not, %v1 |
| 130 | + %and1 = and i64 %v0, %a0 |
| 131 | + %or = or i64 %and0, %and1 |
| 132 | + ret i64 %or |
| 133 | +} |
| 134 | + |
| 135 | +define i32 @not_a_masked_merge0(i32 %a0, i32 %a1, i32 %a2) { |
| 136 | +; RV32-LABEL: not_a_masked_merge0: |
| 137 | +; RV32: # %bb.0: |
| 138 | +; RV32-NEXT: and a1, a0, a1 |
| 139 | +; RV32-NEXT: neg a0, a0 |
| 140 | +; RV32-NEXT: and a0, a0, a2 |
| 141 | +; RV32-NEXT: or a0, a1, a0 |
| 142 | +; RV32-NEXT: ret |
| 143 | +; |
| 144 | +; RV64-LABEL: not_a_masked_merge0: |
| 145 | +; RV64: # %bb.0: |
| 146 | +; RV64-NEXT: and a1, a0, a1 |
| 147 | +; RV64-NEXT: negw a0, a0 |
| 148 | +; RV64-NEXT: and a0, a0, a2 |
| 149 | +; RV64-NEXT: or a0, a1, a0 |
| 150 | +; RV64-NEXT: ret |
| 151 | + %and0 = and i32 %a0, %a1 |
| 152 | + %not_a_not = sub i32 0, %a0 |
| 153 | + %and1 = and i32 %not_a_not, %a2 |
| 154 | + %or = or i32 %and0, %and1 |
| 155 | + ret i32 %or |
| 156 | +} |
| 157 | + |
| 158 | +define i32 @not_a_masked_merge1(i32 %a0, i32 %a1, i32 %a2, i32 %a3) { |
| 159 | +; CHECK-I-LABEL: not_a_masked_merge1: |
| 160 | +; CHECK-I: # %bb.0: |
| 161 | +; CHECK-I-NEXT: and a0, a0, a1 |
| 162 | +; CHECK-I-NEXT: not a1, a3 |
| 163 | +; CHECK-I-NEXT: and a1, a1, a2 |
| 164 | +; CHECK-I-NEXT: or a0, a0, a1 |
| 165 | +; CHECK-I-NEXT: ret |
| 166 | +; |
| 167 | +; CHECK-ZBB-LABEL: not_a_masked_merge1: |
| 168 | +; CHECK-ZBB: # %bb.0: |
| 169 | +; CHECK-ZBB-NEXT: and a0, a0, a1 |
| 170 | +; CHECK-ZBB-NEXT: andn a1, a2, a3 |
| 171 | +; CHECK-ZBB-NEXT: or a0, a0, a1 |
| 172 | +; CHECK-ZBB-NEXT: ret |
| 173 | + %and0 = and i32 %a0, %a1 |
| 174 | + %not = xor i32 %a3, -1 |
| 175 | + %and1 = and i32 %not, %a2 |
| 176 | + %or = or i32 %and0, %and1 |
| 177 | + ret i32 %or |
| 178 | +} |
| 179 | + |
| 180 | +define i32 @not_a_masked_merge2(i32 %a0, i32 %a1, i32 %a2) { |
| 181 | +; CHECK-I-LABEL: not_a_masked_merge2: |
| 182 | +; CHECK-I: # %bb.0: |
| 183 | +; CHECK-I-NEXT: or a1, a0, a1 |
| 184 | +; CHECK-I-NEXT: not a0, a0 |
| 185 | +; CHECK-I-NEXT: and a0, a0, a2 |
| 186 | +; CHECK-I-NEXT: or a0, a1, a0 |
| 187 | +; CHECK-I-NEXT: ret |
| 188 | +; |
| 189 | +; CHECK-ZBB-LABEL: not_a_masked_merge2: |
| 190 | +; CHECK-ZBB: # %bb.0: |
| 191 | +; CHECK-ZBB-NEXT: or a1, a0, a1 |
| 192 | +; CHECK-ZBB-NEXT: andn a0, a2, a0 |
| 193 | +; CHECK-ZBB-NEXT: or a0, a1, a0 |
| 194 | +; CHECK-ZBB-NEXT: ret |
| 195 | + %not_an_and0 = or i32 %a0, %a1 |
| 196 | + %not = xor i32 %a0, -1 |
| 197 | + %and1 = and i32 %not, %a2 |
| 198 | + %or = or i32 %not_an_and0, %and1 |
| 199 | + ret i32 %or |
| 200 | +} |
| 201 | + |
| 202 | +define i32 @not_a_masked_merge3(i32 %a0, i32 %a1, i32 %a2) { |
| 203 | +; CHECK-I-LABEL: not_a_masked_merge3: |
| 204 | +; CHECK-I: # %bb.0: |
| 205 | +; CHECK-I-NEXT: and a1, a0, a1 |
| 206 | +; CHECK-I-NEXT: xor a0, a0, a2 |
| 207 | +; CHECK-I-NEXT: not a0, a0 |
| 208 | +; CHECK-I-NEXT: or a0, a1, a0 |
| 209 | +; CHECK-I-NEXT: ret |
| 210 | +; |
| 211 | +; CHECK-ZBB-LABEL: not_a_masked_merge3: |
| 212 | +; CHECK-ZBB: # %bb.0: |
| 213 | +; CHECK-ZBB-NEXT: and a1, a0, a1 |
| 214 | +; CHECK-ZBB-NEXT: xor a0, a0, a2 |
| 215 | +; CHECK-ZBB-NEXT: orn a0, a1, a0 |
| 216 | +; CHECK-ZBB-NEXT: ret |
| 217 | + %and0 = and i32 %a0, %a1 |
| 218 | + %not = xor i32 %a0, -1 |
| 219 | + %not_an_and1 = xor i32 %not, %a2 |
| 220 | + %or = or i32 %and0, %not_an_and1 |
| 221 | + ret i32 %or |
| 222 | +} |
| 223 | + |
| 224 | +define i32 @not_a_masked_merge4(i32 %a0, i32 %a1, i32 %a2) { |
| 225 | +; CHECK-LABEL: not_a_masked_merge4: |
| 226 | +; CHECK: # %bb.0: |
| 227 | +; CHECK-NEXT: and a0, a0, a1 |
| 228 | +; CHECK-NEXT: ret |
| 229 | + %and0 = and i32 %a0, %a1 |
| 230 | + %not = xor i32 %a2, -1 |
| 231 | + %and1 = and i32 %not, %a2 |
| 232 | + %or = or i32 %and0, %and1 |
| 233 | + ret i32 %or |
| 234 | +} |
| 235 | + |
| 236 | +define i32 @masked_merge_no_transform0(i32 %a0, i32 %a1, i32 %a2, ptr %p1) { |
| 237 | +; CHECK-I-LABEL: masked_merge_no_transform0: |
| 238 | +; CHECK-I: # %bb.0: |
| 239 | +; CHECK-I-NEXT: and a1, a0, a1 |
| 240 | +; CHECK-I-NEXT: not a0, a0 |
| 241 | +; CHECK-I-NEXT: and a0, a0, a2 |
| 242 | +; CHECK-I-NEXT: or a0, a1, a0 |
| 243 | +; CHECK-I-NEXT: sw a1, 0(a3) |
| 244 | +; CHECK-I-NEXT: ret |
| 245 | +; |
| 246 | +; CHECK-ZBB-LABEL: masked_merge_no_transform0: |
| 247 | +; CHECK-ZBB: # %bb.0: |
| 248 | +; CHECK-ZBB-NEXT: and a1, a0, a1 |
| 249 | +; CHECK-ZBB-NEXT: andn a0, a2, a0 |
| 250 | +; CHECK-ZBB-NEXT: or a0, a1, a0 |
| 251 | +; CHECK-ZBB-NEXT: sw a1, 0(a3) |
| 252 | +; CHECK-ZBB-NEXT: ret |
| 253 | + %and0 = and i32 %a0, %a1 |
| 254 | + %not = xor i32 %a0, -1 |
| 255 | + %and1 = and i32 %not, %a2 |
| 256 | + %or = or i32 %and0, %and1 |
| 257 | + store i32 %and0, ptr %p1 |
| 258 | + ret i32 %or |
| 259 | +} |
| 260 | + |
| 261 | +define i32 @masked_merge_no_transform1(i32 %a0, i32 %a1, i32 %a2, ptr %p1) { |
| 262 | +; CHECK-I-LABEL: masked_merge_no_transform1: |
| 263 | +; CHECK-I: # %bb.0: |
| 264 | +; CHECK-I-NEXT: and a1, a0, a1 |
| 265 | +; CHECK-I-NEXT: not a4, a0 |
| 266 | +; CHECK-I-NEXT: and a0, a4, a2 |
| 267 | +; CHECK-I-NEXT: or a0, a1, a0 |
| 268 | +; CHECK-I-NEXT: sw a4, 0(a3) |
| 269 | +; CHECK-I-NEXT: ret |
| 270 | +; |
| 271 | +; CHECK-ZBB-LABEL: masked_merge_no_transform1: |
| 272 | +; CHECK-ZBB: # %bb.0: |
| 273 | +; CHECK-ZBB-NEXT: and a1, a0, a1 |
| 274 | +; CHECK-ZBB-NEXT: not a4, a0 |
| 275 | +; CHECK-ZBB-NEXT: andn a0, a2, a0 |
| 276 | +; CHECK-ZBB-NEXT: or a0, a1, a0 |
| 277 | +; CHECK-ZBB-NEXT: sw a4, 0(a3) |
| 278 | +; CHECK-ZBB-NEXT: ret |
| 279 | + %and0 = and i32 %a0, %a1 |
| 280 | + %not = xor i32 %a0, -1 |
| 281 | + %and1 = and i32 %not, %a2 |
| 282 | + %or = or i32 %and0, %and1 |
| 283 | + store i32 %not, ptr %p1 |
| 284 | + ret i32 %or |
| 285 | +} |
| 286 | + |
| 287 | +define i32 @masked_merge_no_transform2(i32 %a0, i32 %a1, i32 %a2, ptr %p1) { |
| 288 | +; CHECK-I-LABEL: masked_merge_no_transform2: |
| 289 | +; CHECK-I: # %bb.0: |
| 290 | +; CHECK-I-NEXT: and a1, a0, a1 |
| 291 | +; CHECK-I-NEXT: not a0, a0 |
| 292 | +; CHECK-I-NEXT: and a2, a0, a2 |
| 293 | +; CHECK-I-NEXT: or a0, a1, a2 |
| 294 | +; CHECK-I-NEXT: sw a2, 0(a3) |
| 295 | +; CHECK-I-NEXT: ret |
| 296 | +; |
| 297 | +; CHECK-ZBB-LABEL: masked_merge_no_transform2: |
| 298 | +; CHECK-ZBB: # %bb.0: |
| 299 | +; CHECK-ZBB-NEXT: and a1, a0, a1 |
| 300 | +; CHECK-ZBB-NEXT: andn a2, a2, a0 |
| 301 | +; CHECK-ZBB-NEXT: or a0, a1, a2 |
| 302 | +; CHECK-ZBB-NEXT: sw a2, 0(a3) |
| 303 | +; CHECK-ZBB-NEXT: ret |
| 304 | + %and0 = and i32 %a0, %a1 |
| 305 | + %not = xor i32 %a0, -1 |
| 306 | + %and1 = and i32 %not, %a2 |
| 307 | + %or = or i32 %and0, %and1 |
| 308 | + store i32 %and1, ptr %p1 |
| 309 | + ret i32 %or |
| 310 | +} |
0 commit comments