Commit e1009fa
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 6e40a9d commit e1009fa
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 | |
|---|---|---|---|
| |||
9558 | 9558 | | |
9559 | 9559 | | |
9560 | 9560 | | |
9561 | | - | |
9562 | | - | |
9563 | 9561 | | |
9564 | | - | |
9565 | | - | |
9566 | | - | |
9567 | | - | |
9568 | | - | |
9569 | | - | |
9570 | | - | |
9571 | | - | |
9572 | | - | |
9573 | | - | |
9574 | | - | |
9575 | | - | |
9576 | | - | |
9577 | | - | |
| 9562 | + | |
| 9563 | + | |
| 9564 | + | |
9578 | 9565 | | |
9579 | | - | |
9580 | | - | |
9581 | | - | |
9582 | | - | |
| 9566 | + | |
| 9567 | + | |
9583 | 9568 | | |
9584 | | - | |
9585 | | - | |
| 9569 | + | |
| 9570 | + | |
9586 | 9571 | | |
9587 | 9572 | | |
9588 | 9573 | | |
| |||
| 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