[clang] [llvm] [RISCV] Support Xsfvfofp4min assembler version 0.1 (PR #164820)
Brandon Wu via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 15 21:55:17 PST 2026
https://github.com/4vtomat updated https://github.com/llvm/llvm-project/pull/164820
>From 3d8e3c81698800aed13adfe356ed8bc68486ab16 Mon Sep 17 00:00:00 2001
From: Brandon Wu <songwu0813 at gmail.com>
Date: Tue, 29 Apr 2025 13:54:26 +0800
Subject: [PATCH 1/3] [llvm][RISCV] Support Xsfvfofp4min assembler version 0.1
SiFive vendor OFP4 conversion extension Xsfvfofp4min
spec: https://www.sifive.com/document-file/ofp4-conversion-instruction-xsfvfofp4min-extension
---
.../Driver/print-supported-extensions-riscv.c | 1 +
.../riscv-target-features-sifive.c | 8 ++++++
llvm/docs/RISCVUsage.md | 4 +++
llvm/lib/Target/RISCV/RISCVFeatures.td | 8 ++++++
llvm/lib/Target/RISCV/RISCVInstrInfo.td | 1 +
.../RISCV/RISCVInstrInfoXSfvfofp4min.td | 20 +++++++++++++++
llvm/test/CodeGen/RISCV/attributes-sifive.ll | 4 +++
llvm/test/CodeGen/RISCV/features-info.ll | 1 +
llvm/test/MC/RISCV/attribute-arch-sifive.s | 3 +++
llvm/test/MC/RISCV/rvv/xsfvfofp4min.s | 25 +++++++++++++++++++
.../TargetParser/RISCVISAInfoTest.cpp | 1 +
11 files changed, 76 insertions(+)
create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td
create mode 100644 llvm/test/MC/RISCV/rvv/xsfvfofp4min.s
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c b/clang/test/Driver/print-supported-extensions-riscv.c
index 08b3405cfe0486..df6e22716822fe 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -226,6 +226,7 @@
// CHECK-NEXT: xsfvfexpa 0.2 'XSfvfexpa' (SiFive Vector Floating-Point Exponential Approximation Instruction)
// CHECK-NEXT: xsfvfexpa64e 0.2 'XSfvfexpa64e' (SiFive Vector Floating-Point Exponential Approximation Instruction with Double-Precision)
// CHECK-NEXT: xsfvfnrclipxfqf 1.0 'XSfvfnrclipxfqf' (SiFive FP32-to-int8 Ranged Clip Instructions)
+// CHECK-NEXT: xsfvfofp4min 0.1 'XSfvfofp4min' (SiFive Vector OFP4 Conversion Instruction)
// CHECK-NEXT: xsfvfwmaccqqq 1.0 'XSfvfwmaccqqq' (SiFive Matrix Multiply Accumulate Instruction (4-by-4))
// CHECK-NEXT: xsfvqmaccdod 1.0 'XSfvqmaccdod' (SiFive Int8 Matrix Multiplication Instructions (2-by-8 and 8-by-2))
// CHECK-NEXT: xsfvqmaccqoq 1.0 'XSfvqmaccqoq' (SiFive Int8 Matrix Multiplication Instructions (4-by-8 and 8-by-4))
diff --git a/clang/test/Preprocessor/riscv-target-features-sifive.c b/clang/test/Preprocessor/riscv-target-features-sifive.c
index 5002f621b7c39a..5637a7e7e8bdfd 100644
--- a/clang/test/Preprocessor/riscv-target-features-sifive.c
+++ b/clang/test/Preprocessor/riscv-target-features-sifive.c
@@ -210,3 +210,11 @@
// RUN: -march=rv64i_zve32x_xsfmmbase -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-XSFMMBASE %s
// CHECK-XSFMMBASE: __riscv_xsfmmbase 6000{{$}}
+
+// RUN: %clang --target=riscv32 \
+// RUN: -march=rv32i_xsfvfofp4min0p1 -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-XSFVFOFP4MIN-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN: -march=rv64i_xsfvfofp4min0p1 -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-XSFVFOFP4MIN-EXT %s
+// CHECK-XSFVFOFP4MIN-EXT: __riscv_xsfvfofp4min 1000{{$}}
diff --git a/llvm/docs/RISCVUsage.md b/llvm/docs/RISCVUsage.md
index 91ee1385fb7855..0d7762c476076d 100644
--- a/llvm/docs/RISCVUsage.md
+++ b/llvm/docs/RISCVUsage.md
@@ -681,6 +681,10 @@ The current vendor extensions supported are:
: SpacemiT defines the [Integrated Matrix Extension (IME) specification](https://github.com/spacemit-com/docs-ai/blob/main/en/architecture/ime_extension.md)
LLVM implements the hardware-adapted subset for SpacemiT A100
+`Xsfvfofp4min`
+
+: LLVM implements the [0.1 draft specification](https://www.sifive.com/document-file/ofp4-conversion-instruction-xsfvfofp4min-extension) by SiFive.
+
## Experimental C Intrinsics
In some cases an extension is non-experimental but the C intrinsics for that
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 79b90b3b2defbb..214424fc14bb9a 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1634,6 +1634,14 @@ def FeatureVendorXSfsclic
: RISCVExperimentalExtension<0, 1,
"SiFive CLIC Supervisor-mode CSRs">;
+def FeatureVendorXSfvfofp4min
+ : RISCVExtension<0, 1, "SiFive Vector OFP4 Conversion Instruction",
+ [FeatureStdExtZve32f]>;
+def HasVendorXSfvfofp4min
+ : Predicate<"Subtarget->hasVendorXSfvfofp4min()">,
+ AssemblerPredicate<(all_of FeatureVendorXSfvfofp4min),
+ "'XSfvfofp4min' (SiFive Vector OFP4 Conversion Instruction)">;
+
// Core-V Extensions
def FeatureVendorXCVelw
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index d3bdb1ce202e3b..88eed1f24c3f9d 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -2535,6 +2535,7 @@ include "RISCVInstrInfoY.td"
include "RISCVInstrInfoXTHead.td"
include "RISCVInstrInfoXSf.td"
include "RISCVInstrInfoXSfmm.td"
+include "RISCVInstrInfoXSfvfofp4min.td"
include "RISCVInstrInfoXCV.td"
include "RISCVInstrInfoXwch.td"
include "RISCVInstrInfoXqci.td"
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td
new file mode 100644
index 00000000000000..6fe86d8391f07a
--- /dev/null
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td
@@ -0,0 +1,20 @@
+//===- RISCVInstrInfoXSfvfofp4min.td - 'XSfvfofp4min' -----*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file describes the SiFive custom 'XSfvfofp4min' extension, providing
+// vector conversion instructions for OFP4.
+// spec: https://www.sifive.com/document-file/ofp4-conversion-instruction-xsfvfofp4min-extension
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// Instructions
+//===----------------------------------------------------------------------===//
+
+let Predicates = [HasVendorXSfvfofp4min], AltFmtType = IS_NOT_ALTFMT in
+ def VFEXT_VF2 : VEXT_MV_VS2<"sf.vfext.vf2", 0b010010, 0b10110>;
diff --git a/llvm/test/CodeGen/RISCV/attributes-sifive.ll b/llvm/test/CodeGen/RISCV/attributes-sifive.ll
index 8973eb79780969..db5ff8abb41393 100644
--- a/llvm/test/CodeGen/RISCV/attributes-sifive.ll
+++ b/llvm/test/CodeGen/RISCV/attributes-sifive.ll
@@ -13,6 +13,7 @@
; RUN: llc -mtriple=riscv32 -mattr=+xsfmm64a64f %s -o - | FileCheck --check-prefixes=CHECK,RV32XSFMM64A64F %s
; RUN: llc -mtriple=riscv32 -mattr=+xsfmm64t %s -o - | FileCheck --check-prefixes=CHECK,RV32XSFMM64T %s
; RUN: llc -mtriple=riscv32 -mattr=+xsfmmbase %s -o - | FileCheck --check-prefixes=CHECK,RV32XSFMMBASE %s
+; RUN: llc -mtriple=riscv32 -mattr=+xsfvfofp4min %s -o - | FileCheck --check-prefixes=CHECK,RV32XSFVFOFP4MIN %s
; RUN: llc -mtriple=riscv64 -mattr=+xsfmm128t %s -o - | FileCheck --check-prefixes=CHECK,RV64XSFMM128T %s
; RUN: llc -mtriple=riscv64 -mattr=+xsfmm16t %s -o - | FileCheck --check-prefixes=CHECK,RV64XSFMM16T %s
; RUN: llc -mtriple=riscv64 -mattr=+xsfmm32a8i %s -o - | FileCheck --check-prefixes=CHECK,RV64XSFMM32A8I %s
@@ -25,6 +26,7 @@
; RUN: llc -mtriple=riscv64 -mattr=+xsfmmbase %s -o - | FileCheck --check-prefixes=CHECK,RV64XSFMMBASE %s
; RUN: llc -mtriple=riscv64 -mattr=+xsfmm32a %s -o - | FileCheck --check-prefixes=CHECK,RV64XSFMM32A %s
; RUN: llc -mtriple=riscv64 -mattr=+xsfmm32a8i,+xsfmm32a16f,+xsfmm32a32f %s -o - | FileCheck --check-prefixes=CHECK,RV64COMBINEINTOXSFMM32A %s
+; RUN: llc -mtriple=riscv64 -mattr=+xsfvfofp4min %s -o - | FileCheck --check-prefixes=CHECK,RV64XSFVFOFP4MIN %s
; CHECK: .attribute 4, 16
@@ -41,6 +43,7 @@
; RV32XSFMM64A64F: .attribute 5, "rv32i2p1_f2p2_d2p2_zicsr2p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl32b1p0_zvl64b1p0_xsfmm64a64f0p6_xsfmmbase0p6"
; RV32XSFMM64T: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl64b1p0_xsfmm64t0p6_xsfmmbase0p6"
; RV32XSFMMBASE: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_xsfmmbase0p6"
+; RV32XSFVFOFP4MIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvl32b1p0_xsfvfofp4min0p1"
; RV64XSFMM128T: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl512b1p0_zvl64b1p0_xsfmm128t0p6_xsfmmbase0p6"
; RV64XSFMM16T: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_zvl64b1p0_xsfmm16t0p6_xsfmmbase0p6"
; RV64XSFMM32A8I: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_xsfmm32a8i0p6_xsfmmbase0p6"
@@ -53,6 +56,7 @@
; RV64XSFMMBASE: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_xsfmmbase0p6"
; RV64XSFMM32A: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvl32b1p0_xsfmm32a0p6_xsfmm32a16f0p6_xsfmm32a32f0p6_xsfmm32a8i0p6_xsfmmbase0p6"
; RV64COMBINEINTOXSFMM32A: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvl32b1p0_xsfmm32a0p6_xsfmm32a16f0p6_xsfmm32a32f0p6_xsfmm32a8i0p6_xsfmmbase0p6"
+; RV64XSFVFOFP4MIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvl32b1p0_xsfvfofp4min0p1"
define i32 @addi(i32 %a) {
%1 = add i32 %a, 1
diff --git a/llvm/test/CodeGen/RISCV/features-info.ll b/llvm/test/CodeGen/RISCV/features-info.ll
index 4164f9697af651..6f388582a511ca 100644
--- a/llvm/test/CodeGen/RISCV/features-info.ll
+++ b/llvm/test/CodeGen/RISCV/features-info.ll
@@ -284,6 +284,7 @@
; CHECK-NEXT: xsfvfexpa - 'XSfvfexpa' (SiFive Vector Floating-Point Exponential Approximation Instruction).
; CHECK-NEXT: xsfvfexpa64e - 'XSfvfexpa64e' (SiFive Vector Floating-Point Exponential Approximation Instruction with Double-Precision).
; CHECK-NEXT: xsfvfnrclipxfqf - 'XSfvfnrclipxfqf' (SiFive FP32-to-int8 Ranged Clip Instructions).
+; CHECK-NEXT: xsfvfofp4min - 'XSfvfofp4min' (SiFive Vector OFP4 Conversion Instruction).
; CHECK-NEXT: xsfvfwmaccqqq - 'XSfvfwmaccqqq' (SiFive Matrix Multiply Accumulate Instruction (4-by-4)).
; CHECK-NEXT: xsfvqmaccdod - 'XSfvqmaccdod' (SiFive Int8 Matrix Multiplication Instructions (2-by-8 and 8-by-2)).
; CHECK-NEXT: xsfvqmaccqoq - 'XSfvqmaccqoq' (SiFive Int8 Matrix Multiplication Instructions (4-by-8 and 8-by-4)).
diff --git a/llvm/test/MC/RISCV/attribute-arch-sifive.s b/llvm/test/MC/RISCV/attribute-arch-sifive.s
index 45eeb722b8d95e..58e93d34511465 100644
--- a/llvm/test/MC/RISCV/attribute-arch-sifive.s
+++ b/llvm/test/MC/RISCV/attribute-arch-sifive.s
@@ -32,3 +32,6 @@
.attribute arch, "rv32i_xsfmmbase"
# CHECK: attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_xsfmmbase0p6"
+
+.attribute arch, "rv32i_xsfvfofp4min0p1"
+# CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvl32b1p0_xsfvfofp4min0p1"
diff --git a/llvm/test/MC/RISCV/rvv/xsfvfofp4min.s b/llvm/test/MC/RISCV/rvv/xsfvfofp4min.s
new file mode 100644
index 00000000000000..0ddc682173dc7f
--- /dev/null
+++ b/llvm/test/MC/RISCV/rvv/xsfvfofp4min.s
@@ -0,0 +1,25 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding -mattr=+xsfvfofp4min %s \
+# RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN: | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+xsfvfofp4min %s \
+# RUN: | llvm-objdump -d --mattr=+xsfvfofp4min - \
+# RUN: | FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -show-encoding -mattr=+xsfvfofp4min %s \
+# RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN: | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+xsfvfofp4min %s \
+# RUN: | llvm-objdump -d --mattr=+xsfvfofp4min - \
+# RUN: | FileCheck %s --check-prefix=CHECK-INST
+
+
+# CHECK-INST: sf.vfext.vf2 v8, v4
+# CHECK-ENCODING: [0x57,0x24,0x4b,0x4a]
+# CHECK-ERROR: instruction requires the following: 'XSfvfofp4min' (SiFive Vector OFP4 Conversion Instruction){{$}}
+sf.vfext.vf2 v8, v4
+
+# CHECK-INST: sf.vfext.vf2 v8, v4, v0.t
+# CHECK-ENCODING: [0x57,0x24,0x4b,0x48]
+# CHECK-ERROR: instruction requires the following: 'XSfvfofp4min' (SiFive Vector OFP4 Conversion Instruction){{$}}
+sf.vfext.vf2 v8, v4, v0.t
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index fc1301b45963c6..9a0577059f2de4 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -1746,6 +1746,7 @@ R"(All available -march extensions for RISC-V
xsfvfexpa 0.2
xsfvfexpa64e 0.2
xsfvfnrclipxfqf 1.0
+ xsfvfofp4min 0.1
xsfvfwmaccqqq 1.0
xsfvqmaccdod 1.0
xsfvqmaccqoq 1.0
>From 2aaba944441b5f842870eb4d051fcd8c335ed366 Mon Sep 17 00:00:00 2001
From: Brandon Wu <brandon.wu at sifive.com>
Date: Sun, 15 Nov 2026 20:49:48 -0800
Subject: [PATCH 2/3] fixup! fix Craig's comments
---
llvm/docs/RISCVUsage.md | 8 ++++----
llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/docs/RISCVUsage.md b/llvm/docs/RISCVUsage.md
index 0d7762c476076d..2fcb201de36376 100644
--- a/llvm/docs/RISCVUsage.md
+++ b/llvm/docs/RISCVUsage.md
@@ -499,6 +499,10 @@ The current vendor extensions supported are:
: LLVM implements [version 1.0.0 of the Matrix Multiply Accumulate Instruction Extension Specification](https://sifive.cdn.prismic.io/sifive/c391d53e-ffcf-4091-82f6-c37bf3e883ed_xsfvfwmaccqqq-spec.pdf) by SiFive. All instructions are prefixed with `sf.` as described in the specification linked above.
+`Xsfvfofp4min`
+
+: LLVM implements the [0.1 draft specification](https://www.sifive.com/document-file/ofp4-conversion-instruction-xsfvfofp4min-extension) by SiFive.
+
`XCVbitmanip`
: LLVM implements [version 1.0.0 of the CORE-V Bit Manipulation custom instructions specification](https://github.com/openhwgroup/cv32e40p/blob/62bec66b36182215e18c9cf10f723567e23878e9/docs/source/instruction_set_extensions.rst) by OpenHW Group. All instructions are prefixed with `cv.` as described in the specification.
@@ -681,10 +685,6 @@ The current vendor extensions supported are:
: SpacemiT defines the [Integrated Matrix Extension (IME) specification](https://github.com/spacemit-com/docs-ai/blob/main/en/architecture/ime_extension.md)
LLVM implements the hardware-adapted subset for SpacemiT A100
-`Xsfvfofp4min`
-
-: LLVM implements the [0.1 draft specification](https://www.sifive.com/document-file/ofp4-conversion-instruction-xsfvfofp4min-extension) by SiFive.
-
## Experimental C Intrinsics
In some cases an extension is non-experimental but the C intrinsics for that
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td
index 6fe86d8391f07a..40099763a2b549 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXSfvfofp4min.td
@@ -1,4 +1,4 @@
-//===- RISCVInstrInfoXSfvfofp4min.td - 'XSfvfofp4min' -----*- tablegen -*-===//
+//===- RISCVInstrInfoXSfvfofp4min.td - 'XSfvfofp4min' ------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From 1ab8d49c0f28e3bdb88ae5d73a7f509ad0efd5a2 Mon Sep 17 00:00:00 2001
From: Brandon Wu <songwu0813 at gmail.com>
Date: Mon, 16 Nov 2026 13:55:07 +0800
Subject: [PATCH 3/3] Update llvm/lib/Target/RISCV/RISCVFeatures.td
Co-authored-by: Craig Topper <craig.topper at sifive.com>
---
llvm/lib/Target/RISCV/RISCVFeatures.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 214424fc14bb9a..31aa326febb5f4 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1640,7 +1640,7 @@ def FeatureVendorXSfvfofp4min
def HasVendorXSfvfofp4min
: Predicate<"Subtarget->hasVendorXSfvfofp4min()">,
AssemblerPredicate<(all_of FeatureVendorXSfvfofp4min),
- "'XSfvfofp4min' (SiFive Vector OFP4 Conversion Instruction)">;
+ "'XSfvfofp4min' (SiFive Vector OFP4 Conversion Instruction)">;
// Core-V Extensions
More information about the cfe-commits
mailing list