Commit fa2a6d6
authored
[CodeGenPrepare][RISCV] Combine (X ^ Y) and (X == Y) where appropriate (llvm#130922)
Fixes llvm#130510.
In RISCV, modify the folding of (X ^ Y == 0) -> (X == Y) to account for
cases where the (X ^ Y) will be re-used.
If a constant is being used for the XOR before a branch, ensure that it
is small enough to fit within a 12-bit immediate field. Otherwise, the
equality check is more efficient than the check against 0, see the
following:
```
# %bb.0:
lui a1, 5
addiw a1, a1, 1365
xor a0, a0, a1
beqz a0, .LBB0_2
# %bb.1:
ret
.LBB0_2:
```
```
# %bb.0:
lui a1, 5
addiw a1, a1, 1365
beq a0, a1, .LBB0_2
# %bb.1:
xor a0, a0, a1
ret
.LBB0_2:
```
Similarly, if the XOR is between 1 and a size one integer, we should
still fold away the XOR since that comparison can be optimized as a
comparison against 0.
```
# %bb.0:
slt a0, a0, a1
xor a0, a0, 1
beqz a0, .LBB0_2
# %bb.1:
ret
.LBB0_2:
```
```
# %bb.0:
slt a0, a0, a1
bnez a0, .LBB0_2
# %bb.1:
xor a0, a0, 1
ret
.LBB0_2:
```
One question about my code is that I used a hard-coded value for the
width of a RISCV ALU immediate. Do you know of a way that I can gather
this from the `context`, I was unable to devise one.1 parent 74ec038 commit fa2a6d6
File tree
3 files changed
+121
-2
lines changed- llvm
- lib
- CodeGen
- Target/RISCV
- test/CodeGen/RISCV
3 files changed
+121
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8575 | 8575 | | |
8576 | 8576 | | |
8577 | 8577 | | |
8578 | | - | |
| 8578 | + | |
| 8579 | + | |
8579 | 8580 | | |
8580 | 8581 | | |
8581 | 8582 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17400 | 17400 | | |
17401 | 17401 | | |
17402 | 17402 | | |
| 17403 | + | |
| 17404 | + | |
| 17405 | + | |
| 17406 | + | |
| 17407 | + | |
| 17408 | + | |
| 17409 | + | |
| 17410 | + | |
| 17411 | + | |
| 17412 | + | |
| 17413 | + | |
| 17414 | + | |
| 17415 | + | |
| 17416 | + | |
| 17417 | + | |
| 17418 | + | |
| 17419 | + | |
| 17420 | + | |
| 17421 | + | |
| 17422 | + | |
| 17423 | + | |
| 17424 | + | |
| 17425 | + | |
| 17426 | + | |
| 17427 | + | |
| 17428 | + | |
| 17429 | + | |
| 17430 | + | |
| 17431 | + | |
| 17432 | + | |
| 17433 | + | |
| 17434 | + | |
17403 | 17435 | | |
17404 | | - | |
| 17436 | + | |
17405 | 17437 | | |
17406 | 17438 | | |
17407 | 17439 | | |
17408 | 17440 | | |
| 17441 | + | |
| 17442 | + | |
| 17443 | + | |
| 17444 | + | |
| 17445 | + | |
| 17446 | + | |
| 17447 | + | |
| 17448 | + | |
| 17449 | + | |
| 17450 | + | |
| 17451 | + | |
| 17452 | + | |
17409 | 17453 | | |
17410 | 17454 | | |
17411 | 17455 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 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 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
0 commit comments