Skip to content

Commit 40c2aaf

Browse files
authored
[RISCV][sema] Correct the requirement of vf[n|w]cvt.x[|u].f intrinsics (llvm#101811)
Fix llvm#101526 `vf[n|w]cvt.x[|u].f` for f16 needs `zvfh` instead of `zvfhmin`, current approach is not able to detect this. Ultimately we need to add `zvfh` to RequiredFeatures to check other intrinsics instead, the type check should be done in checkRVVTypeSupport.
1 parent 6a59dea commit 40c2aaf

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

clang/include/clang/Basic/riscv_vector.td

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,8 +1918,18 @@ def vfcvt_rtz_x_f_v : RVVConvToSignedBuiltin<"vfcvt_rtz_x">;
19181918
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
19191919
def vfwcvt_rtz_xu_f_v : RVVConvToWidenUnsignedBuiltin<"vfwcvt_rtz_xu">;
19201920
def vfwcvt_rtz_x_f_v : RVVConvToWidenSignedBuiltin<"vfwcvt_rtz_x">;
1921-
def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "csi", "vfwcvt_f">;
1922-
def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "csi", "vfwcvt_f">;
1921+
def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "si", "vfwcvt_f">;
1922+
def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "si", "vfwcvt_f">;
1923+
let RequiredFeatures = ["Zvfh"] in {
1924+
let Name = "vfwcvt_f_xu_v",
1925+
IRName = "vfwcvt_f_xu_v",
1926+
MaskedIRName = "vfwcvt_f_xu_v_mask" in
1927+
def : RVVConvBuiltin<"Fw", "FwUv", "c", "vfwcvt_f">;
1928+
let Name = "vfwcvt_f_x_v",
1929+
IRName = "vfwcvt_f_x_v",
1930+
MaskedIRName = "vfwcvt_f_x_v_mask" in
1931+
def : RVVConvBuiltin<"Fw", "Fwv", "c", "vfwcvt_f">;
1932+
}
19231933
def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
19241934
let RequiredFeatures = ["Zvfhmin"] in
19251935
def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {
@@ -1933,6 +1943,16 @@ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
19331943
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
19341944
def vfncvt_rtz_xu_f_w : RVVConvToNarrowingUnsignedBuiltin<"vfncvt_rtz_xu">;
19351945
def vfncvt_rtz_x_f_w : RVVConvToNarrowingSignedBuiltin<"vfncvt_rtz_x">;
1946+
let RequiredFeatures = ["Zvfh"] in {
1947+
let Name = "vfncvt_rtz_xu_f_w",
1948+
IRName = "vfncvt_rtz_xu_f_w",
1949+
MaskedIRName = "vfncvt_rtz_xu_f_w_mask" in
1950+
def : RVVConvBuiltin<"Uv", "UvFw", "c", "vfncvt_rtz_xu">;
1951+
let Name = "vfncvt_rtz_x_f_w",
1952+
IRName = "vfncvt_rtz_x_f_w",
1953+
MaskedIRName = "vfncvt_rtz_x_f_w_mask" in
1954+
def : RVVConvBuiltin<"Iv", "IvFw", "c", "vfncvt_rtz_x">;
1955+
}
19361956
def vfncvt_rod_f_f_w : RVVConvBuiltin<"v", "vw", "xf", "vfncvt_rod_f">;
19371957
}
19381958

@@ -2011,10 +2031,18 @@ let ManualCodegen = [{
20112031
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
20122032
let OverloadedName = "vfncvt_x" in
20132033
defm :
2014-
RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFwu"]]>;
2034+
RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFwu"]]>;
20152035
let OverloadedName = "vfncvt_xu" in
20162036
defm :
2017-
RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFwu"]]>;
2037+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFwu"]]>;
2038+
let RequiredFeatures = ["Zvfh"] in {
2039+
let OverloadedName = "vfncvt_x" in
2040+
defm :
2041+
RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvFwu"]]>;
2042+
let OverloadedName = "vfncvt_xu" in
2043+
defm :
2044+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "c", [["Uv", "UvFwu"]]>;
2045+
}
20182046
let OverloadedName = "vfncvt_f" in {
20192047
defm :
20202048
RVVConvBuiltinSet<"vfncvt_f_x_w", "xf", [["v", "vIwu"]]>;
@@ -2061,10 +2089,18 @@ let ManualCodegen = [{
20612089
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
20622090
let OverloadedName = "vfncvt_x" in
20632091
defm :
2064-
RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFw"]]>;
2092+
RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFw"]]>;
20652093
let OverloadedName = "vfncvt_xu" in
20662094
defm :
2067-
RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFw"]]>;
2095+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFw"]]>;
2096+
let RequiredFeatures = ["Zvfh"] in {
2097+
let OverloadedName = "vfncvt_x" in
2098+
defm :
2099+
RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvFw"]]>;
2100+
let OverloadedName = "vfncvt_xu" in
2101+
defm :
2102+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "c", [["Uv", "UvFw"]]>;
2103+
}
20682104
let OverloadedName = "vfncvt_f" in {
20692105
defm :
20702106
RVVConvBuiltinSet<"vfncvt_f_x_w", "xf", [["v", "vIw"]]>;

clang/include/clang/Basic/riscv_vector_common.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@ class RVVConvToWidenUnsignedBuiltin<string overloaded_name>
604604
: RVVConvBuiltin<"Uw", "Uwv", "xf", overloaded_name>;
605605

606606
class RVVConvToNarrowingSignedBuiltin<string overloaded_name>
607-
: RVVConvBuiltin<"Iv", "IvFw", "csi", overloaded_name>;
607+
: RVVConvBuiltin<"Iv", "IvFw", "si", overloaded_name>;
608608

609609
class RVVConvToNarrowingUnsignedBuiltin<string overloaded_name>
610-
: RVVConvBuiltin<"Uv", "UvFw", "csi", overloaded_name>;
610+
: RVVConvBuiltin<"Uv", "UvFw", "si", overloaded_name>;
611611

612612
let HasMaskedOffOperand = true in {
613613
multiclass RVVSignedReductionBuiltin {

clang/include/clang/Support/RISCVVIntrinsicUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ enum RVVRequire : uint32_t {
502502
RVV_REQ_Zvksh = 1 << 15,
503503
RVV_REQ_Zvfbfwma = 1 << 16,
504504
RVV_REQ_Zvfbfmin = 1 << 17,
505-
RVV_REQ_Experimental = 1 << 18,
505+
RVV_REQ_Zvfh = 1 << 18,
506+
RVV_REQ_Experimental = 1 << 19,
506507

507508
LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Experimental)
508509
};

clang/lib/Sema/SemaRISCV.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
222222
{"zvksh", RVV_REQ_Zvksh},
223223
{"zvfbfwma", RVV_REQ_Zvfbfwma},
224224
{"zvfbfmin", RVV_REQ_Zvfbfmin},
225+
{"zvfh", RVV_REQ_Zvfh},
225226
{"experimental", RVV_REQ_Experimental}};
226227

227228
// Construction of RVVIntrinsicRecords need to sync with createRVVIntrinsics
@@ -280,6 +281,11 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
280281
if ((BaseTypeI & Record.TypeRangeMask) != BaseTypeI)
281282
continue;
282283

284+
// TODO: Remove the check below and use RequiredFeatures in
285+
// riscv_vector.td to check the intrinsics instead, the type check should
286+
// be done in checkRVVTypeSupport. This check also not able to work on the
287+
// intrinsics that have Float16 but the BaseType is not Float16 such as
288+
// `vfcvt_f_x_v`.
283289
if (BaseType == BasicType::Float16) {
284290
if ((Record.RequiredExtensions & RVV_REQ_Zvfhmin) == RVV_REQ_Zvfhmin) {
285291
if (!TI.hasFeature("zvfhmin"))

clang/utils/TableGen/RISCVVEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ void RVVEmitter::createRVVIntrinsics(
670670
.Case("Zvksh", RVV_REQ_Zvksh)
671671
.Case("Zvfbfwma", RVV_REQ_Zvfbfwma)
672672
.Case("Zvfbfmin", RVV_REQ_Zvfbfmin)
673+
.Case("Zvfh", RVV_REQ_Zvfh)
673674
.Case("Experimental", RVV_REQ_Experimental)
674675
.Default(RVV_REQ_None);
675676
assert(RequireExt != RVV_REQ_None && "Unrecognized required feature?");

0 commit comments

Comments
 (0)