Skip to content

Commit fe46a46

Browse files
committed
Add test for zicond zf/dinx select lowering
* Floating-point `select` is lowered through Zicond only when both Zicond and Zfinx/Zdinx extensions are enabled. * When both Zicond and Zfinx/Zdinx are enabled, branch-based lowering is replaced by a Zicond-backed integer `select` (no control-flow branches are emitted for these cases).
1 parent 329a5d0 commit fe46a46

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
; RUN: llc -mtriple=riscv64 -mattr=+zfinx,+zicond -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64ZFINX_ZICOND
2+
; RUN: llc -mtriple=riscv64 -mattr=+zfinx -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64ZFINX_NOZICOND
3+
; RUN: llc -mtriple=riscv64 -mattr=+zdinx,+zicond -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64ZDINX_ZICOND
4+
; RUN: llc -mtriple=riscv64 -mattr=+zdinx -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64ZDINX_NOZICOND
5+
; RUN: llc -mtriple=riscv64 -mattr=+f -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64F
6+
; RUN: llc -mtriple=riscv64 -mattr=+d -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64D
7+
8+
; RUN: llc -mtriple=riscv32 -mattr=+zfinx,+zicond -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV32ZFINX_ZICOND
9+
; RUN: llc -mtriple=riscv32 -mattr=+zfinx -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV32ZFINX_NOZICOND
10+
; RUN: llc -mtriple=riscv32 -mattr=+f -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV32F
11+
12+
13+
; This test checks that floating-point SELECT is lowered through integer
14+
; SELECT (and thus to Zicond czero.* sequence) when FP values live in GPRs
15+
; (Zfinx/Zdinx) and Zicond is enabled. When Zicond is disabled, we expect
16+
; a branch-based lowering instead.
17+
18+
; -----------------------------------------------------------------------------
19+
; float select with i1 condition (Zfinx)
20+
; -----------------------------------------------------------------------------
21+
22+
define float @select_f32_i1(i1 %cond, float %t, float %f) nounwind {
23+
; RV64ZFINX_ZICOND-LABEL: select_f32_i1:
24+
; RV64ZFINX_ZICOND: czero
25+
; RV64ZFINX_ZICOND: czero
26+
; RV64ZFINX_ZICOND: or
27+
; RV64ZFINX_ZICOND-NOT: b{{(eq|ne)z?}}
28+
; RV64ZFINX_ZICOND: ret
29+
30+
; RV64ZFINX_NOZICOND-LABEL: select_f32_i1:
31+
; RV64ZFINX_NOZICOND: b{{(eq|ne)z?}}
32+
; RV64ZFINX_NOZICOND-NOT: czero.eqz
33+
; RV64ZFINX_NOZICOND-NOT: czero.nez
34+
35+
; RV64F-LABEL: select_f32_i1:
36+
; RV64F: b{{(eq|ne)z?}}
37+
; RV64F-NOT: czero.eqz
38+
; RV64F-NOT: czero.nez
39+
40+
; RV32ZFINX_ZICOND-LABEL: select_f32_i1:
41+
; RV32ZFINX_ZICOND: czero
42+
; RV32ZFINX_ZICOND: czero
43+
; RV32ZFINX_ZICOND: or
44+
; RV32ZFINX_ZICOND-NOT: b{{(eq|ne)z?}}
45+
; RV32ZFINX_ZICOND: ret
46+
47+
; RV32ZFINX_NOZICOND-LABEL: select_f32_i1:
48+
; RV32ZFINX_NOZICOND: b{{(eq|ne)z?}}
49+
; RV32ZFINX_NOZICOND-NOT: czero.eqz
50+
; RV32ZFINX_NOZICOND-NOT: czero.nez
51+
52+
; RV32F-LABEL: select_f32_i1:
53+
; RV32F: b{{(eq|ne)z?}}
54+
; RV32F-NOT: czero.eqz
55+
; RV32F-NOT: czero.nez
56+
57+
entry:
58+
%sel = select i1 %cond, float %t, float %f
59+
ret float %sel
60+
}
61+
62+
; -----------------------------------------------------------------------------
63+
; double select with i1 condition (Zdinx)
64+
; -----------------------------------------------------------------------------
65+
66+
define double @select_f64_i1(i1 %cond, double %t, double %f) nounwind {
67+
; RV64ZDINX_ZICOND-LABEL: select_f64_i1:
68+
; RV64ZDINX_ZICOND: czero
69+
; RV64ZDINX_ZICOND: czero
70+
; RV64ZDINX_ZICOND: or
71+
; RV64ZDINX_ZICOND-NOT: b{{(eq|ne)z?}}
72+
; RV64ZDINX_ZICOND: ret
73+
74+
; RV64ZDINX_NOZICOND-LABEL: select_f64_i1:
75+
; RV64ZDINX_NOZICOND: b{{(eq|ne)z?}}
76+
; RV64ZDINX_NOZICOND-NOT: czero.eqz
77+
; RV64ZDINX_NOZICOND-NOT: czero.nez
78+
79+
; RV64D-LABEL: select_f64_i1:
80+
; RV64D: b{{(eq|ne)z?}}
81+
; RV64D-NOT: czero.eqz
82+
; RV64D-NOT: czero.nez
83+
84+
entry:
85+
%sel = select i1 %cond, double %t, double %f
86+
ret double %sel
87+
}
88+
89+
; -----------------------------------------------------------------------------
90+
; double select with floating-point compare condition (a > b ? c : d), Zdinx
91+
; -----------------------------------------------------------------------------
92+
93+
define double @select_f64_fcmp(double %a, double %b, double %c, double %d) nounwind {
94+
; RV64ZDINX_ZICOND-LABEL: select_f64_fcmp:
95+
; RV64ZDINX_ZICOND: czero
96+
; RV64ZDINX_ZICOND: czero
97+
; RV64ZDINX_ZICOND: or
98+
; RV64ZDINX_ZICOND-NOT: b{{(eq|ne)z?}}
99+
; RV64ZDINX_ZICOND: ret
100+
101+
; RV64ZDINX_NOZICOND-LABEL: select_f64_fcmp:
102+
; RV64ZDINX_NOZICOND: b{{(eq|ne)z?}}
103+
; RV64ZDINX_NOZICOND-NOT: czero.eqz
104+
; RV64ZDINX_NOZICOND-NOT: czero.nez
105+
106+
; RV64D-LABEL: select_f64_fcmp:
107+
; RV64D: b{{(eq|ne)z?}}
108+
; RV64D-NOT: czero.eqz
109+
; RV64D-NOT: czero.nez
110+
111+
entry:
112+
%cmp = fcmp ogt double %a, %b
113+
%sel = select i1 %cmp, double %c, double %d
114+
ret double %sel
115+
}

0 commit comments

Comments
 (0)