[clang] 743905e - [RISC-V][MC][RVY] Introduce support for the Zyhybrid extension (#233969)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 3 21:28:16 PST 2026
Author: Alexander Richardson
Date: 2026-11-03T21:28:09-08:00
New Revision: 743905e1f847704358d93bb06faf8c018ebdeb32
URL: https://github.com/llvm/llvm-project/commit/743905e1f847704358d93bb06faf8c018ebdeb32
DIFF: https://github.com/llvm/llvm-project/commit/743905e1f847704358d93bb06faf8c018ebdeb32.diff
LOG: [RISC-V][MC][RVY] Introduce support for the Zyhybrid extension (#233969)
RVY supports two execution modes: Capability Pointer Mode, where all memory
operands are YLEN-wide capability pointers, and Integral Pointer Mode where
the hart is compatible with RVI binaries (but supports the RVY instructions).
Zyhybrid adds instructions to dynamically switch between these modes.
Technically, the base ISA is RVY in both modes: RVY repurposes the custom-3
opcode space, which cannot be done by a non-vendor extension and therefore
must be a new base ISA. However, Integral Pointer Mode is effectively RVI
just with some formerly vendor opcode space reserved. Following RISC-V ARC
guidance, it is represented in the arch string as rv{32,64}i_zyhybrid rather
than rv{32,64}y plus some kind of "rvi_compat" extension. This means we can
use FeatureStdExtY to directly track Capability Pointer Mode and encode the
four possible execution states as follows:
- -y, -zyhybrid: Standard RVI (no RVY support, custom-3 is vendor space).
- +y, -zyhybrid: RVY in Capability Pointer Mode (cannot switch modes).
- +y, +zyhybrid: RVY in Capability Pointer Mode with Zyhybrid to switch mode.
- -y, +zyhybrid: RVY in Integral Pointer Mode (RVI compatible, but custom-3
no longer reserved for vendor extension).
Therefore, this commit changes the predicate for RVY instructions to
`FeatureStdExtY || FeatureStdExtZyhybrid` and uses FeatureStdExtY only for
the capability pointer mode. This is not really used in this commit yet,
but is needed to support the mode-dependent load/store/jump operands.
Switching the pointer mode currently requires a full architecture string
in `.option arch` (`.option arch, +y/-y` is rejected for now since it
requires more invasive changes).
Co-authored-by: Jessica Clarke <jrtc27 at jrtc27.com>
Assisted-by: AI tooling (test cases)
Pull-Request: https://github.com/llvm/llvm-project/pull/233969
Added:
llvm/test/MC/Disassembler/RISCV/rvy-zyhybrid-invalid.txt
llvm/test/MC/RISCV/rvy/rvy-option-arch.s
llvm/test/MC/RISCV/rvy/rvy-zyhybrid-invalid.s
llvm/test/MC/RISCV/rvy/rvy-zyhybrid.s
Modified:
clang/test/Driver/print-supported-extensions-riscv.c
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfoY.td
llvm/lib/Target/RISCV/RISCVRegisterInfo.td
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/CodeGen/RISCV/features-info.ll
llvm/test/MC/RISCV/rvy/rvy-basic-invalid.s
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
Removed:
################################################################################
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c b/clang/test/Driver/print-supported-extensions-riscv.c
index 46c43092810608..08b3405cfe0486 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -252,6 +252,7 @@
// CHECK-NEXT: zibi 0.1 'Zibi' (Branch with Immediate)
// CHECK-NEXT: zicfilp 1.0 'Zicfilp' (Landing pad)
// CHECK-NEXT: zilx 0.1 'Zilx' (Indexed Integer Load Instructions)
+// CHECK-NEXT: zyhybrid 0.910 'Zyhybrid' (Hybrid Extension for RVI Compatibility)
// CHECK-NEXT: zvabd 0.9 'Zvabd' (Vector Absolute Difference)
// CHECK-NEXT: zvbc32e 0.7 'Zvbc32e' (Vector Carryless Multiplication with 32-bits elements)
// CHECK-NEXT: zvdot4a8i 0.1 'Zvdot4a8i' (Vector 4-element Dot Product of packed 8-bit Integers)
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 1aae893b21cb2f..0e319505c3ce04 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1410,6 +1410,11 @@ static MCRegister convertFPR64ToFPR256(MCRegister Reg) {
return Reg - RISCV::F0_D + RISCV::F0_Q2;
}
+static bool regClassIsYGPR(const MCRegisterClass &RC) {
+ assert(RC.getNumRegs() > 0);
+ return getRISCVMCRegisterClass(RISCV::YGPRRegClassID).contains(*RC.begin());
+}
+
unsigned RISCVAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
unsigned Kind) {
RISCVOperand &Op = static_cast<RISCVOperand &>(AsmOp);
@@ -1423,10 +1428,18 @@ unsigned RISCVAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
getRISCVMCRegisterClass(RISCV::FPR64CRegClassID).contains(Reg);
bool IsRegVR = getRISCVMCRegisterClass(RISCV::VRRegClassID).contains(Reg);
- if (Op.isGPR() && Kind == MCK_YGPR) {
- // GPR and capability GPR use the same register names, convert if required.
- Op.Reg.Reg = convertGPRToYGPR(Reg);
- return Match_Success;
+ // YGPR and GPR use the same register names in assembly, so convert GPR
+ // operands to YGPR when matching a YGPR register class (such as YGPRNoX0).
+ if (Op.isGPR()) {
+ const MCRegisterClass *RC =
+ getRegClassFromMatchKind(static_cast<MatchClassKind>(Kind));
+ if (RC && regClassIsYGPR(*RC)) {
+ MCRegister YReg = convertGPRToYGPR(Reg);
+ if (RC->contains(YReg)) {
+ Op.Reg.Reg = YReg;
+ return Match_Success;
+ }
+ }
}
if (IsRegFPR64 && Kind == MCK_FPR256) {
Op.Reg.Reg = convertFPR64ToFPR256(Reg);
@@ -3369,6 +3382,10 @@ bool RISCVAsmParser::parseDirectiveOption() {
if (Ext == std::end(AllFeatures) || StringRef(Ext->key()) != Feature)
return Error(Loc, "unknown extension feature");
+ if (Ext->Value == RISCV::FeatureStdExtY)
+ return Error(Loc, "passing '+y'/'-y' is not supported yet; specify a "
+ "full arch string instead");
+
Args.emplace_back(Type, Arch.str());
if (Type == RISCVOptionArchArgType::Plus) {
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 39fd0ce574dbc5..3bc886cfc954cb 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -131,6 +131,8 @@ static DecodeStatus DecodeSingleRegister(MCInst &Inst,
constexpr auto DecodeGPRRegisterClass =
DecodeSimpleRegisterClass<RISCV::X0, 32, /*RVELimit=*/16>;
+constexpr auto DecodeYGPRRegisterClass =
+ DecodeSimpleRegisterClass<RISCV::X0_Y, 32, /*RVELimit=*/16>;
template <auto DecodeFn, auto PredicateFn>
static DecodeStatus DecodeFilteredRegisterClass(MCInst &Inst, uint32_t RegNo,
@@ -148,6 +150,8 @@ constexpr bool PredX1OrX5(uint32_t RegNo) { return RegNo == 1 || RegNo == 5; }
constexpr auto DecodeGPRNoX0RegisterClass =
DecodeFilteredRegisterClass<DecodeGPRRegisterClass, PredNoX0>;
+constexpr auto DecodeYGPRNoX0RegisterClass =
+ DecodeFilteredRegisterClass<DecodeYGPRRegisterClass, PredNoX0>;
constexpr auto DecodeGPRNoX2RegisterClass =
DecodeFilteredRegisterClass<DecodeGPRRegisterClass, PredNoX2>;
constexpr auto DecodeGPRNoX31RegisterClass =
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td
index f91b2691cf3376..6c94edcee2c715 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1325,11 +1325,42 @@ def HasStdExtZbkbOrP
"'Zbkb' (Bitmanip instructions for Cryptography) or "
"'Base P' (Packed-SIMD)">;
-// "Y" extension (CHERI support)
-
-def FeatureStdExtY : RISCVExperimentalExtension<0, 910, "'Base Y' (CHERI)">;
-def HasStdExtY : Predicate<"Subtarget->hasStdExtY()">,
- AssemblerPredicate<(all_of FeatureStdExtY), "'Base Y' (CHERI)">;
+// "Y" base ISA and Zyhybrid extension (CHERI support)
+//
+// RVY supports two execution modes: Capability Pointer Mode, where all memory
+// operands are YLEN-wide capability pointers, and Integral Pointer Mode where
+// the hart is compatible with RVI binaries (but supports the RVY instructions).
+// Zyhybrid adds instructions to dynamically switch between these modes.
+//
+// Technically, the base ISA is RVY in both modes: RVY repurposes the custom-3
+// opcode space, which cannot be done by a non-vendor extension and therefore
+// must be a new base ISA. However, Integral Pointer Mode is effectively RVI
+// just with some formerly vendor opcode space reserved. Following RISC-V ARC
+// guidance, it is represented in the arch string as rv{32,64}i_zyhybrid rather
+// than rv{32,64}y plus some kind of "rvi_compat" extension. This means we can
+// use FeatureStdExtY to directly track Capability Pointer Mode and encode the
+// four possible execution states as follows:
+// - -y, -zyhybrid: Standard RVI (no RVY support, custom-3 is vendor space).
+// - +y, -zyhybrid: RVY in Capability Pointer Mode (cannot switch modes).
+// - +y, +zyhybrid: RVY in Capability Pointer Mode with Zyhybrid to switch mode.
+// - -y, +zyhybrid: RVY in Integral Pointer Mode (RVI compatible, but custom-3
+// no longer reserved for vendor extension).
+def FeatureStdExtY
+ : RISCVExperimentalExtension<0, 910, "'Base Y' (CHERI)", [],
+ "HasStdExtYCapMode">;
+def FeatureStdExtZyhybrid
+ : RISCVExperimentalExtension<0, 910,
+ "Hybrid Extension for RVI Compatibility">;
+
+def HasYInstructions
+ : Predicate<"Subtarget->hasYInstructions()">,
+ AssemblerPredicate<(any_of FeatureStdExtY, FeatureStdExtZyhybrid),
+ "'Base Y' (CHERI) or "
+ "'Zyhybrid' (Hybrid Extension for RVI Compatibility)">;
+def HasStdExtZyhybrid
+ : Predicate<"Subtarget->hasStdExtZyhybrid()">,
+ AssemblerPredicate<(all_of FeatureStdExtZyhybrid),
+ "'Zyhybrid' (Hybrid Extension for RVI Compatibility)">;
//===----------------------------------------------------------------------===//
// Vendor extensions
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoY.td b/llvm/lib/Target/RISCV/RISCVInstrInfoY.td
index ba5e08a1185027..aedce23e3d8d18 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoY.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoY.td
@@ -36,10 +36,10 @@ def ybndsw_imm : RISCVOp<XLenVT>, ImmLeaf<XLenVT, [{
//===----------------------------------------------------------------------===//
// Instruction Formats and class templates
//===----------------------------------------------------------------------===//
-
-let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
// All regular 3-operand RVY instructions use opc=CUSTOM-3/RVY-A with funct3=0
defvar OPC_RVY_A = OPC_CUSTOM_3;
+
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
class RVY_rr<bits<7> funct7, string opcodestr, DAGOperand rdOp,
DAGOperand rs1Op, DAGOperand rs2Op>
: RVInstR<funct7, 0b000, OPC_RVY_A, (outs rdOp:$rd),
@@ -91,7 +91,7 @@ class RVY_bndswi<string opcodestr>
}
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
-let Predicates = [HasStdExtY] in {
+let Predicates = [HasYInstructions] in {
//
// Instructions to Update The Capability Pointer
//
@@ -141,4 +141,22 @@ def YHIR : RVY_r_xy<0b00111, "yhir">;
def YEQ : RVY_rr<0b0000110, "yeq", GPR, YGPR, YGPR>;
def YSS : RVY_rr<0b0001110, "yss", GPR, YGPR, YGPR>;
def YAMASK : RVY_r_xx<0b00000, "yamask">;
-} // Predicates = [HasStdExtY]
+} // Predicates = [HasYInstructions]
+
+//===----------------------------------------------------------------------===//
+// Zyhybrid extension (Hybrid Extension for RVI Compatibility)
+//===----------------------------------------------------------------------===//
+// YMODESW[YI] is encoded as YMODEW with rd=x0, rs1=x0, rs2=mode.
+let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
+class RVY_modesw<bits<5> mode, string opcodestr>
+ : RVInstR<0b0101011, 0b000, OPC_RVY_A, (outs), (ins), opcodestr, ""> {
+ let rs2 = mode;
+ let rs1 = 0;
+ let rd = 0;
+}
+let Predicates = [HasStdExtZyhybrid] in {
+def YMODER : RVY_r_xy<0b00110, "ymoder">;
+def YMODEW : RVY_rr<0b0101011, "ymodew", YGPRNoX0, YGPR, GPR>;
+def YMODESWY : RVY_modesw<0b00000, "ymodeswy">;
+def YMODESWI : RVY_modesw<0b00001, "ymodeswi">;
+} // Predicates = [HasStdExtZyhybrid]
diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td
index e8b7ee8a91f731..42637beacb8ce8 100644
--- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td
@@ -313,6 +313,11 @@ class GPRRegisterClass<dag regList>
let RegInfos = XLenRI;
}
+class YGPRRegisterClass<dag regList>
+ : RISCVRegisterClass<[YLenVT], 64, regList> {
+ let RegInfos = YLenRI;
+}
+
// The order of registers represents the preferred allocation sequence.
// Registers are listed in the order caller-save, callee-save, specials.
def GPR : GPRRegisterClass<(add (sequence "X%u", 10, 17),
@@ -325,15 +330,13 @@ def GPR : GPRRegisterClass<(add (sequence "X%u", 10, 17),
let DiagnosticString = "register must be a GPR";
}
-def YGPR : RegisterClass<"RISCV", [YLenVT], 64,
- (add (sequence "X%u_Y", 10, 17),
- (sequence "X%u_Y", 5, 7),
- (sequence "X%u_Y", 28, 31),
- (sequence "X%u_Y", 8, 9),
- (sequence "X%u_Y", 18, 27),
- (sequence "X%u_Y", 0, 4))> {
- let RegInfos = YLenRI;
- let DecoderMethod = "DecodeSimpleRegisterClass<RISCV::X0_Y, 32, /*RVELimit=*/16>";
+def YGPR : YGPRRegisterClass<(add (sequence "X%u_Y", 10, 17),
+ (sequence "X%u_Y", 5, 7),
+ (sequence "X%u_Y", 28, 31),
+ (sequence "X%u_Y", 8, 9),
+ (sequence "X%u_Y", 18, 27),
+ (sequence "X%u_Y", 0, 4))> {
+ let DiagnosticString = GPR.DiagnosticString;
}
def GPRX0 : GPRRegisterClass<(add X0)> {
@@ -357,6 +360,9 @@ def GPRNoX0 : GPRRegisterClass<(sub GPR, X0)> {
let DiagnosticType = "InvalidRegClassGPRNoX0";
let DiagnosticString = "register must be a GPR excluding zero (x0)";
}
+def YGPRNoX0 : YGPRRegisterClass<(sub YGPR, X0_Y)> {
+ let DiagnosticString = GPRNoX0.DiagnosticString;
+}
def GPRNoX2 : GPRRegisterClass<(sub GPR, X2)> {
let DiagnosticType = "InvalidRegClassGPRNoX2";
diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h
index 9a2397e1777127..52fb7e4c5289f7 100644
--- a/llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -188,6 +188,9 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
bool GETTER() const { return ATTRIBUTE; }
#include "RISCVGenSubtargetInfo.inc"
+ bool hasYInstructions() const {
+ return HasStdExtYCapMode || HasStdExtZyhybrid;
+ }
bool hasStdExtZvl() const { return ZvlLen != 0; }
bool hasStdExtFOrZfinx() const { return HasStdExtF || HasStdExtZfinx; }
bool hasStdExtDOrZdinx() const { return HasStdExtD || HasStdExtZdinx; }
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll
index a2ed361b43a4b0..44e2a7568ea0aa 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -343,6 +343,8 @@
; RUN: llc -mtriple=riscv64 -mattr=+sdtrig %s -o - | FileCheck --check-prefix=RV64SDTRIG %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-p %s -o - | FileCheck --check-prefix=RV64P %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-y -target-abi lp64 %s -o - | FileCheck --check-prefix=RV64Y %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-y,+experimental-zyhybrid -target-abi lp64 %s -o - | FileCheck --check-prefix=RV64Y-ZYHYBRID %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zyhybrid -target-abi lp64 %s -o - | FileCheck --check-prefix=RV64I-ZYHYBRID %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zibi %s -o - | FileCheck --check-prefix=RV64ZIBI %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zilx %s -o - | FileCheck --check-prefix=RV64ZILX %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zvqwbdota8i %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVQWBDOTA8I %s
@@ -712,6 +714,8 @@
; RV64SDTRIG: .attribute 5, "rv64i2p1_sdtrig1p0"
; RV64P: .attribute 5, "rv64i2p1_p0p21_zicsr2p0_zmmul1p0_zba1p0_zbb1p0"
; RV64Y: .attribute 5, "rv64y0p910"
+; RV64Y-ZYHYBRID: .attribute 5, "rv64y0p910_zyhybrid0p910"
+; RV64I-ZYHYBRID: .attribute 5, "rv64i2p1_zyhybrid0p910"
; RV64ZIBI: .attribute 5, "rv64i2p1_zibi0p1"
; RV64ZVQWBDOTA8I: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zvl32b1p0_zvqwbdota8i0p2"
; RV64ZVQWBDOTA16I: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zve64x1p0_zvl32b1p0_zvl64b1p0_zvqwbdota16i0p2"
diff --git a/llvm/test/CodeGen/RISCV/features-info.ll b/llvm/test/CodeGen/RISCV/features-info.ll
index b999fb062862ba..4164f9697af651 100644
--- a/llvm/test/CodeGen/RISCV/features-info.ll
+++ b/llvm/test/CodeGen/RISCV/features-info.ll
@@ -67,6 +67,7 @@
; CHECK-NEXT: experimental-zvvmtls - 'Zvvmtls' (Matrix Tile Load/Store).
; CHECK-NEXT: experimental-zvvmttls - 'Zvvmttls' (Transposing Matrix Tile Load/Store).
; CHECK-NEXT: experimental-zvzip - 'Zvzip' (Vector Reordering Structured Data).
+; CHECK-NEXT: experimental-zyhybrid - 'Zyhybrid' (Hybrid Extension for RVI Compatibility).
; CHECK-NEXT: f - 'F' (Single-Precision Floating-Point).
; CHECK-NEXT: forced-atomics - Assume that lock-free native-width atomics are available.
; CHECK-NEXT: fusion-add-load - Enable ADD(.UW) + load macrofusion.
diff --git a/llvm/test/MC/Disassembler/RISCV/rvy-zyhybrid-invalid.txt b/llvm/test/MC/Disassembler/RISCV/rvy-zyhybrid-invalid.txt
new file mode 100644
index 00000000000000..ae2e225495cfe7
--- /dev/null
+++ b/llvm/test/MC/Disassembler/RISCV/rvy-zyhybrid-invalid.txt
@@ -0,0 +1,13 @@
+# RUN: not llvm-mc --disassemble --triple=riscv32 --mattr=+experimental-zyhybrid %s 2>&1 \
+# RUN: | FileCheck %s
+# RUN: not llvm-mc --disassemble --triple=riscv64 --mattr=+experimental-zyhybrid %s 2>&1 \
+# RUN: | FileCheck %s
+
+## YMODEW with rd=x0 is reserved unless rs1=x0 and rs2 selects a valid mode
+## (i.e. ymodeswy/ymodeswi).
+[0x7b,0x00,0x20,0x56]
+# CHECK: :[[#@LINE-1]]:2: warning: invalid instruction encoding
+[0x7b,0x80,0x05,0x56]
+# CHECK: :[[#@LINE-1]]:2: warning: invalid instruction encoding
+[0x7b,0x80,0xc5,0x56]
+# CHECK: :[[#@LINE-1]]:2: warning: invalid instruction encoding
diff --git a/llvm/test/MC/RISCV/rvy/rvy-basic-invalid.s b/llvm/test/MC/RISCV/rvy/rvy-basic-invalid.s
index d4088f3646d4ae..7b80d39acc0579 100644
--- a/llvm/test/MC/RISCV/rvy/rvy-basic-invalid.s
+++ b/llvm/test/MC/RISCV/rvy/rvy-basic-invalid.s
@@ -34,3 +34,13 @@ ybndswi a0, a0, 8192
// CHECK: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [1, 255], a multiple of 8 in the range [256, 504], or a multiple of 16 in the range [512, 4096]
ybndswi a0, a0, 4112
// CHECK: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [1, 255], a multiple of 8 in the range [256, 504], or a multiple of 16 in the range [512, 4096]
+
+/// Zyhybrid instructions are not part of the base Y extension.
+ymoder a0, a1
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
+ymodew a0, a1, a2
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
+ymodeswy
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
+ymodeswi
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
diff --git a/llvm/test/MC/RISCV/rvy/rvy-option-arch.s b/llvm/test/MC/RISCV/rvy/rvy-option-arch.s
new file mode 100644
index 00000000000000..d45c9f4dde458f
--- /dev/null
+++ b/llvm/test/MC/RISCV/rvy/rvy-option-arch.s
@@ -0,0 +1,107 @@
+/// Check the interaction of `.option` directives with ymodeswy/ymodeswi.
+
+// RUN: split-file %s %t
+// RUN: llvm-mc --triple=riscv64 --mattr=+experimental,+experimental-zyhybrid,+c,+d \
+// RUN: --filetype=obj %t/rv64.s -o %t/rv64.o
+// RUN: llvm-objdump -d --show-all-symbols %t/rv64.o | FileCheck %t/rv64.s
+// RUN: llvm-mc --triple=riscv32 --mattr=+experimental,+experimental-zyhybrid,+c,+f \
+// RUN: --filetype=obj %t/rv32.s -o %t/rv32.o
+// RUN: llvm-objdump -d --show-all-symbols %t/rv32.o | FileCheck %t/rv32.s
+// RUN: not llvm-mc --triple=riscv32 --mattr=+experimental,+experimental-zyhybrid,+c,+d \
+// RUN: %t/invalid.s 2>&1 | FileCheck %t/invalid.s --check-prefixes=CHECK,RV32 --implicit-check-not=error:
+// RUN: not llvm-mc --triple=riscv64 --mattr=+experimental,+experimental-zyhybrid,+c,+d --defsym=RV64=1 \
+// RUN: %t/invalid.s 2>&1 | FileCheck %t/invalid.s --check-prefixes=CHECK,RV64 --implicit-check-not=error:
+
+//--- rv64.s
+/// Start in RVI compatibility mode: C+D implies Zcd.
+ymodeswi
+// CHECK-LABEL: <$xrv64i2p1_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0_zcd1p0>:
+// CHECK-NEXT: ymodeswi
+
+/// `.option pop` restores the mode from before `.option push`.
+.option push
+ymodeswy
+// CHECK-NEXT: ymodeswy
+/// TODO: This `.option arch` should be implicit in `ymodeswy`.
+.option arch, rv64y0p910_c_d_zyhybrid0p910
+nop
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv64y0p910_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0>:
+// CHECK-NEXT: nop
+.option pop
+
+/// `.option norvc` and `.option rvc` in capability pointer mode must not imply
+/// Zcd until switching back to RVI compatibility mode.
+ymodeswy
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv64i2p1_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0_zcd1p0>:
+// CHECK-NEXT: ymodeswy
+/// TODO: This `.option arch` should be implicit in `ymodeswy`.
+.option arch, rv64y0p910_c_d_zyhybrid0p910
+nop
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv64y0p910_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0>:
+// CHECK-NEXT: nop
+.option norvc
+nop
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv64y0p910_f2p2_d2p2_zicsr2p0_zyhybrid0p910>:
+// CHECK-NEXT: nop
+.option rvc
+ymodeswi
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv64y0p910_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0>:
+// CHECK-NEXT: ymodeswi
+/// TODO: This `.option arch` should be implicit in `ymodeswi`.
+.option arch, rv64i_c_d_zyhybrid0p910
+nop
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv64i2p1_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0_zcd1p0>:
+// CHECK-NEXT: nop
+// CHECK-EMPTY:
+
+//--- rv32.s
+/// Zcd is compatible with RV32Y, so only Zcf is omitted in capability mode.
+.option arch, +d
+ymodeswy
+// CHECK-LABEL: <$xrv32i2p1_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0_zcd1p0_zcf1p0>:
+// CHECK-NEXT: ymodeswy
+/// TODO: This `.option arch` should be implicit in `ymodeswy`.
+.option arch, rv32y0p910_c_d_zyhybrid0p910
+ymodeswi
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv32y0p910_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0_zcd1p0>:
+// CHECK-NEXT: ymodeswi
+/// TODO: This `.option arch` should be implicit in `ymodeswi`.
+.option arch, rv32i_c_d_zyhybrid0p910
+nop
+// CHECK-EMPTY:
+// CHECK-NEXT: <$xrv32i2p1_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0_zcd1p0_zcf1p0>:
+// CHECK-NEXT: nop
+// CHECK-EMPTY:
+
+//--- invalid.s
+/// TODO: Support switching between rv*i and rv*y via `.option arch, +y/-y`.
+.option arch, +y
+// CHECK: :[[#@LINE-1]]:16: error: passing '+y'/'-y' is not supported yet; specify a full arch string instead
+.option arch, -y
+// CHECK: :[[#@LINE-1]]:16: error: passing '+y'/'-y' is not supported yet; specify a full arch string instead
+
+/// Extensions that conflict with RVY cannot be enabled in capability pointer mode.
+ymodeswy
+/// TODO: This `.option arch` should be implicit in `ymodeswy`.
+.ifdef RV64
+.option arch, rv64y0p910_c_d_zyhybrid0p910
+.option arch, +zcd
+// RV64: :[[#@LINE-1]]:16: error: 'zcd' is incompatible with rv64y base
+.option arch, +zcmp
+// RV64: :[[#@LINE-1]]:16: error: 'zcmp' is incompatible with rv64y base
+.option arch, +zcmt
+// RV64: :[[#@LINE-1]]:16: error: 'zcmt' is incompatible with rv64y base
+.else
+.option arch, rv32y0p910_c_d_zyhybrid0p910
+.option arch, +zcf
+// RV32: :[[#@LINE-1]]:16: error: 'zcf' is incompatible with rv32y base
+.option arch, +zclsd
+// RV32: :[[#@LINE-1]]:16: error: 'zclsd' is incompatible with rv32y base
+.endif
diff --git a/llvm/test/MC/RISCV/rvy/rvy-zyhybrid-invalid.s b/llvm/test/MC/RISCV/rvy/rvy-zyhybrid-invalid.s
new file mode 100644
index 00000000000000..18cc80c35ff082
--- /dev/null
+++ b/llvm/test/MC/RISCV/rvy/rvy-zyhybrid-invalid.s
@@ -0,0 +1,21 @@
+// RUN: not llvm-mc --triple riscv32 --mattr=+experimental,+experimental-zyhybrid,+c,+d <%s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=CHECK --implicit-check-not=error:
+// RUN: not llvm-mc --triple riscv64 --mattr=+experimental,+experimental-zyhybrid,+c,+d --defsym=RV64=1 <%s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=CHECK --implicit-check-not=error:
+
+ymodew x0, a0, a0
+// CHECK: :[[#@LINE-1]]:8: error: register must be a GPR excluding zero (x0)
+ymodew f0, a0, a0
+// CHECK: :[[#@LINE-1]]:8: error: register must be a GPR excluding zero (x0)
+yadd f0, a0, a0
+// CHECK: :[[#@LINE-1]]:6: error: register must be a GPR
+
+.option arch, -zyhybrid
+ymoder a0, a1
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
+ymodew a0, a1, a2
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
+ymodeswy
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
+ymodeswi
+// CHECK: :[[#@LINE-1]]:1: error: instruction requires the following: 'Zyhybrid' (Hybrid Extension for RVI Compatibility){{$}}
diff --git a/llvm/test/MC/RISCV/rvy/rvy-zyhybrid.s b/llvm/test/MC/RISCV/rvy/rvy-zyhybrid.s
new file mode 100644
index 00000000000000..34d95222e5876e
--- /dev/null
+++ b/llvm/test/MC/RISCV/rvy/rvy-zyhybrid.s
@@ -0,0 +1,68 @@
+// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --use-same-for-encoding --version 6
+// RUN: llvm-mc --triple=riscv32 --mattr=+experimental,+experimental-y,+experimental-zyhybrid,+c,+f --riscv-no-aliases --show-encoding --show-inst < %s \
+// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-ASM-AND-OBJ
+// RUN: llvm-mc --triple=riscv64 --mattr=+experimental,+experimental-y,+experimental-zyhybrid,+c,+d --defsym=RV64=1 --riscv-no-aliases --show-encoding --show-inst < %s \
+// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-ASM-AND-OBJ
+// RUN: llvm-mc --filetype=obj --triple=riscv32 --mattr=+experimental,+experimental-y,+experimental-zyhybrid,+c,+f --riscv-add-build-attributes < %s -o %t.rv32.o
+// RUN: llvm-objdump -M no-aliases --no-print-imm-hex -d %t.rv32.o | FileCheck %s --check-prefixes=CHECK-ASM-AND-OBJ
+// RUN: llvm-readelf -A %t.rv32.o | FileCheck %s --check-prefix=ATTR-RV32
+// RUN: llvm-mc --filetype=obj --triple=riscv64 --mattr=+experimental,+experimental-y,+experimental-zyhybrid,+c,+d --defsym=RV64=1 --riscv-add-build-attributes < %s -o %t.rv64.o
+// RUN: llvm-objdump -M no-aliases --no-print-imm-hex -d %t.rv64.o | FileCheck %s --check-prefixes=CHECK-ASM-AND-OBJ
+// RUN: llvm-readelf -A %t.rv64.o | FileCheck %s --check-prefix=ATTR-RV64
+
+ymoder a0, a1
+// CHECK-ASM-AND-OBJ: ymoder a0, a1
+// CHECK-SAME: # encoding: [0x7b,0x85,0x65,0xf4]
+// CHECK-NEXT: # <MCInst #[[#MCINST1:]] YMODER{{$}}
+// CHECK-NEXT: # <MCOperand Reg:X10>
+// CHECK-NEXT: # <MCOperand Reg:X11_Y>>
+ymodew a0, a1, a2
+// CHECK-ASM-AND-OBJ: ymodew a0, a1, a2
+// CHECK-SAME: # encoding: [0x7b,0x85,0xc5,0x56]
+// CHECK-NEXT: # <MCInst #[[#MCINST2:]] YMODEW{{$}}
+// CHECK-NEXT: # <MCOperand Reg:X10_Y>
+// CHECK-NEXT: # <MCOperand Reg:X11_Y>
+// CHECK-NEXT: # <MCOperand Reg:X12>>
+
+/// RVY instructions remain available in RVI compatibility mode.
+ymodeswi
+// CHECK-ASM-AND-OBJ: ymodeswi
+// CHECK-SAME: # encoding: [0x7b,0x00,0x10,0x56]
+// CHECK-NEXT: # <MCInst #[[#MCINST3:]] YMODESWI>{{$}}
+/// TODO: This `.option arch` should be implicit in `ymodeswi`.
+.ifdef RV64
+.option arch, rv64i_c_d_zyhybrid0p910
+.else
+.option arch, rv32i_c_f_zyhybrid0p910
+.endif
+yadd a0, a1, a2
+// CHECK-ASM-AND-OBJ: yadd a0, a1, a2
+// CHECK-SAME: # encoding: [0x7b,0x85,0xc5,0x06]
+// CHECK-NEXT: # <MCInst #[[#MCINST4:]] YADD{{$}}
+// CHECK-NEXT: # <MCOperand Reg:X10_Y>
+// CHECK-NEXT: # <MCOperand Reg:X11_Y>
+// CHECK-NEXT: # <MCOperand Reg:X12>>
+
+ymodeswy
+// CHECK-ASM-AND-OBJ: ymodeswy
+// CHECK-SAME: # encoding: [0x7b,0x00,0x00,0x56]
+// CHECK-NEXT: # <MCInst #[[#MCINST5:]] YMODESWY>{{$}}
+/// TODO: This `.option arch` should be implicit in `ymodeswy`.
+.ifdef RV64
+.option arch, rv64y0p910_c_d_zyhybrid0p910
+.else
+.option arch, rv32y0p910_c_f_zyhybrid0p910
+.endif
+yadd a0, a1, a2
+// CHECK-ASM-AND-OBJ: yadd a0, a1, a2
+// CHECK-SAME: # encoding: [0x7b,0x85,0xc5,0x06]
+// CHECK-NEXT: # <MCInst #[[#MCINST4]] YADD{{$}}
+// CHECK-NEXT: # <MCOperand Reg:X10_Y>
+// CHECK-NEXT: # <MCOperand Reg:X11_Y>
+// CHECK-NEXT: # <MCOperand Reg:X12>>
+
+// ATTR-RV32: TagName: arch
+// ATTR-RV32-NEXT: Value: rv32y0p910_f2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0{{$}}
+
+// ATTR-RV64: TagName: arch
+// ATTR-RV64-NEXT: Value: rv64y0p910_f2p2_d2p2_c2p0_zicsr2p0_zyhybrid0p910_zca1p0{{$}}
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 6894939c4ac5b8..b049ec7328868f 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -1771,6 +1771,7 @@ Experimental extensions
zibi 0.1
zicfilp 1.0 This is a long dummy description
zilx 0.1
+ zyhybrid 0.910
zvabd 0.9
zvbc32e 0.7
zvdot4a8i 0.1
More information about the cfe-commits
mailing list