Commit 2e21bb8
authored
[RISCV][ISelLowering] Use Zicond for FP selects on Zfinx/Zdinx (llvm#169299)
### Summary
This patch let RISCVTargetLowering::lowerSELECT to lower some
floating-point select operations through an integer zicond select when:
* Zicond is available, and
* FP values live in GPRs (Zfinx/Zdinx), and
* Select condition is an integer type.
In that scenario there is no extra cost for GPR <-> "FP GPR" moves, so
we can implement FP selects with a CZERO-based sequence instead of a
branch.
For example, for
```c
float foo(int cond, float x) {
return (cond != 0) ? x : 0.0f;
}
```
the current lowering produces:
```asm
foo:
mv a2, a0
li a0, 0
beqz a2, .LBB0_2
.LBB0_1:
mv a0, a1
.LBB0_2:
ret
```
With this patch, when targeting rv64ima_zicond_zfinx we instead get:
```asm
foo:
czero.nez a2, zero, a0
czero.eqz a0, a1, a0
or a0, a2, a0
ret
```
The existing branch-based lowering is preserved for:
* targets without Zicond
* targets where FP registers are separate (+f, +d without zfinx/zdinx)
### Testing
Adds llvm/test/CodeGen/RISCV/zicond-fp-select-zfinx.ll to cover:
* RV64 Zfinx/Zicond vs Zfinx without Zicond
* RV64 Zdinx/Zicond vs Zdinx without Zicond
* RV32 Zfinx/Zicond vs Zfinx without Zicond
Also adds baseline RV32F/RV64F/RV64D cases to ensure we still use
branches when FP registers are separate.
The tests check that:
* With Zicond + Zfinx/Zdinx, FP select lowers to a CZERO+OR sequence
with no conditional branches.
* Without Zicond (or without Zfinx/Zdinx), we still get branch-based
code and no czero.* instructions.1 parent e110abc commit 2e21bb8
File tree
2 files changed
+842
-0
lines changed- llvm
- lib/Target/RISCV
- test/CodeGen/RISCV
2 files changed
+842
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9584 | 9584 | | |
9585 | 9585 | | |
9586 | 9586 | | |
| 9587 | + | |
| 9588 | + | |
| 9589 | + | |
| 9590 | + | |
| 9591 | + | |
| 9592 | + | |
| 9593 | + | |
| 9594 | + | |
| 9595 | + | |
| 9596 | + | |
| 9597 | + | |
| 9598 | + | |
| 9599 | + | |
| 9600 | + | |
| 9601 | + | |
| 9602 | + | |
| 9603 | + | |
| 9604 | + | |
| 9605 | + | |
| 9606 | + | |
| 9607 | + | |
| 9608 | + | |
| 9609 | + | |
| 9610 | + | |
| 9611 | + | |
| 9612 | + | |
| 9613 | + | |
| 9614 | + | |
| 9615 | + | |
| 9616 | + | |
| 9617 | + | |
| 9618 | + | |
| 9619 | + | |
| 9620 | + | |
| 9621 | + | |
| 9622 | + | |
| 9623 | + | |
| 9624 | + | |
| 9625 | + | |
| 9626 | + | |
| 9627 | + | |
| 9628 | + | |
| 9629 | + | |
| 9630 | + | |
9587 | 9631 | | |
9588 | 9632 | | |
9589 | 9633 | | |
| |||
0 commit comments