Commit dafc8b5
committed
Skip Zicond for FP sel when we need to split regs
This patch disables the Zicond optimization for floating-point selects
when the value type exceeds XLen (e.g., f64 on RV32 +zdinx).
In these cases, using Zicond requires handling split registers, which
results in a higher dynamic instruction count compared to the standard
branch-based lowering (e.g., ~8 instructions vs ~5-7 instructions for
appended sample code).
Thus, there is no benefit to using Zicond here
```asm
define double @select_f64_fcmp(double %a, double %b,
double %c, double %d) nounwind {
entry:
%cmp = fcmp ogt double %a, %b
%sel = select i1 %cmp, double %c, double %d
ret double %sel
}
```
Branch version: Executes 5 or 7 instruction
```asm
; RV32ZDINX_NOZICOND-LABEL: select_f64_fcmp:
; RV32ZDINX_NOZICOND: # %bb.0: # %entry
; RV32ZDINX_NOZICOND-NEXT: flt.d a0, a2, a0
; RV32ZDINX_NOZICOND-NEXT: bnez a0, .LBB2_2
; RV32ZDINX_NOZICOND-NEXT: # %bb.1: # %entry
; RV32ZDINX_NOZICOND-NEXT: mv a4, a6
; RV32ZDINX_NOZICOND-NEXT: mv a5, a7
; RV32ZDINX_NOZICOND-NEXT: .LBB2_2: # %entry
; RV32ZDINX_NOZICOND-NEXT: mv a0, a4
; RV32ZDINX_NOZICOND-NEXT: mv a1, a5
; RV32ZDINX_NOZICOND-NEXT: ret
```
Zicond version: Always executes 8 instructions.
```asm
; RV32ZDINX_ZICOND-LABEL: select_f64_fcmp:
; RV32ZDINX_ZICOND: # %bb.0: # %entry
; RV32ZDINX_ZICOND-NEXT: flt.d a0, a2, a0
; RV32ZDINX_ZICOND-NEXT: czero.nez a1, a6, a0
; RV32ZDINX_ZICOND-NEXT: czero.eqz a2, a4, a0
; RV32ZDINX_ZICOND-NEXT: czero.nez a3, a7, a0
; RV32ZDINX_ZICOND-NEXT: czero.eqz a4, a5, a0
; RV32ZDINX_ZICOND-NEXT: or a0, a2, a1
; RV32ZDINX_ZICOND-NEXT: or a1, a4, a3
; RV32ZDINX_ZICOND-NEXT: ret
```1 parent 23f5ad7 commit dafc8b5
File tree
2 files changed
+27
-34
lines changed- llvm
- lib/Target/RISCV
- test/CodeGen/RISCV
2 files changed
+27
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9587 | 9587 | | |
9588 | 9588 | | |
9589 | 9589 | | |
9590 | | - | |
9591 | | - | |
9592 | 9590 | | |
9593 | | - | |
9594 | | - | |
9595 | | - | |
9596 | | - | |
9597 | | - | |
9598 | | - | |
9599 | | - | |
9600 | | - | |
9601 | | - | |
9602 | | - | |
9603 | | - | |
9604 | | - | |
9605 | | - | |
9606 | | - | |
| 9591 | + | |
| 9592 | + | |
| 9593 | + | |
9607 | 9594 | | |
9608 | | - | |
9609 | | - | |
9610 | | - | |
9611 | | - | |
| 9595 | + | |
| 9596 | + | |
9612 | 9597 | | |
9613 | | - | |
9614 | | - | |
| 9598 | + | |
| 9599 | + | |
9615 | 9600 | | |
9616 | 9601 | | |
9617 | 9602 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
187 | 194 | | |
188 | 195 | | |
189 | 196 | | |
| |||
319 | 326 | | |
320 | 327 | | |
321 | 328 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
328 | 336 | | |
329 | 337 | | |
330 | 338 | | |
| |||
0 commit comments