[clang] [llvm] [RISC-V][RVY] Rank 'y' after 'i' and 'e' in canonical extension order (PR #227865)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 13:52:05 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Alexander Richardson (arichardson)

<details>
<summary>Changes</summary>

Because 'y' is only valid as a base ISA letter in parseArchString and
not in AllStdExts, singleLetterExtensionRank previously fell through to
the unknown single-letter extension case and placed 'y' (and 'zy*'
extensions) after all standard single-letter extensions. Rank 'y'
immediately after 'i' and 'e' so that normalized ISA strings place 'y'
before 'm', 'a', 'f', 'd', 'c' and 'zy*' right after 'zi*'.

This commit was created with the help of AI tools

---
Full diff: https://github.com/llvm/llvm-project/pull/227865.diff


4 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1-1) 
- (modified) llvm/lib/Support/RISCVISAUtils.cpp (+4-2) 
- (modified) llvm/test/MC/RISCV/rvy-build-attributes.s (+7-7) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+11-4) 


``````````diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c b/clang/test/Driver/print-supported-extensions-riscv.c
index f916bef0a6519..1d1714314d6e2 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -247,8 +247,8 @@
 // CHECK-NEXT:     xwchc                2.2       'Xwchc' (WCH/QingKe additional compressed opcodes)
 // CHECK-EMPTY:
 // CHECK-NEXT: Experimental extensions
-// CHECK-NEXT:     p                    0.21      'P' ('Base P' (Packed SIMD))
 // CHECK-NEXT:     y                    0.910     'Y' ('Base Y' (CHERI))
+// CHECK-NEXT:     p                    0.21      'P' ('Base P' (Packed SIMD))
 // 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)
diff --git a/llvm/lib/Support/RISCVISAUtils.cpp b/llvm/lib/Support/RISCVISAUtils.cpp
index d6b002e66e7ab..2166d2f30bbb9 100644
--- a/llvm/lib/Support/RISCVISAUtils.cpp
+++ b/llvm/lib/Support/RISCVISAUtils.cpp
@@ -44,15 +44,17 @@ static unsigned singleLetterExtensionRank(char Ext) {
     return 0;
   case 'e':
     return 1;
+  case 'y':
+    return 2;
   }
 
   size_t Pos = RISCVISAUtils::AllStdExts.find(Ext);
   if (Pos != StringRef::npos)
-    return Pos + 2; // Skip 'e' and 'i' from above.
+    return Pos + 3; // Skip 'e', 'i', and 'y' from above.
 
   // If we got an unknown extension letter, then give it an alphabetical
   // order, but after all known standard extensions.
-  return 2 + RISCVISAUtils::AllStdExts.size() + (Ext - 'a');
+  return 3 + RISCVISAUtils::AllStdExts.size() + (Ext - 'a');
 }
 
 // Get the rank for multi-letter extension, lower value meaning higher
diff --git a/llvm/test/MC/RISCV/rvy-build-attributes.s b/llvm/test/MC/RISCV/rvy-build-attributes.s
index f7db55b382ec8..b5abbcb31a8d6 100644
--- a/llvm/test/MC/RISCV/rvy-build-attributes.s
+++ b/llvm/test/MC/RISCV/rvy-build-attributes.s
@@ -14,22 +14,22 @@
 # RUN:   -mattr=+experimental-y,+zce,+f | FileCheck %s --check-prefix=RV32Y-ZCE-F
 
 ## RV64Y + D + C: y is enabled, so zcd is not implied.
-# RV64YDC: .attribute 5, "rv64i2p1_f2p2_d2p2_c2p0_y0p910_zicsr2p0_zca1p0"
+# RV64YDC: .attribute 5, "rv64i2p1_y0p910_f2p2_d2p2_c2p0_zicsr2p0_zca1p0"
 
 ## RV32Y + F + C: y is enabled, so zcf is not implied.
-# RV32YFC: .attribute 5, "rv32i2p1_f2p2_c2p0_y0p910_zicsr2p0_zca1p0"
+# RV32YFC: .attribute 5, "rv32i2p1_y0p910_f2p2_c2p0_zicsr2p0_zca1p0"
 
 ## RV32Y + ZCA + F: zca + y implies c on RV32 (y replaces zcf in the implication).
-# RV32Y-ZCA-F: .attribute 5, "rv32i2p1_f2p2_c2p0_y0p910_zicsr2p0_zca1p0"
+# RV32Y-ZCA-F: .attribute 5, "rv32i2p1_y0p910_f2p2_c2p0_zicsr2p0_zca1p0"
 
 ## RV64Y + ZCA + D: zca + y implies c on RV64 (y replaces zcd in the implication).
-# RV64Y-ZCA-D: .attribute 5, "rv64i2p1_f2p2_d2p2_c2p0_y0p910_zicsr2p0_zca1p0"
+# RV64Y-ZCA-D: .attribute 5, "rv64i2p1_y0p910_f2p2_d2p2_c2p0_zicsr2p0_zca1p0"
 
 ## RV64Y + ZCA + ZCB: zca + zcb + y does NOT imply zce on RV64Y because Zce is incompatible. zca also implies c.
-# RV64Y-ZCA-ZCB: .attribute 5, "rv64i2p1_c2p0_y0p910_zca1p0_zcb1p0"
+# RV64Y-ZCA-ZCB: .attribute 5, "rv64i2p1_y0p910_c2p0_zca1p0_zcb1p0"
 
 ## RV32Y + ZCE: zce implies zca, zcb, zcmp, zcmt. zca implies c.
-# RV32Y-ZCE: .attribute 5, "rv32i2p1_c2p0_y0p910_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0"
+# RV32Y-ZCE: .attribute 5, "rv32i2p1_y0p910_c2p0_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0"
 
 ## RV32Y + ZCE + F: y is enabled, so zcf is not implied by zce + f. zca + y + f implies c.
-# RV32Y-ZCE-F: .attribute 5, "rv32i2p1_f2p2_c2p0_y0p910_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0"
+# RV32Y-ZCE-F: .attribute 5, "rv32i2p1_y0p910_f2p2_c2p0_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0"
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 3994eaf599a82..9c6077bb41e80 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -415,6 +415,13 @@ TEST(RISCVISAInfoTest, CanonicalExtensionOrderVP) {
       Info.toString(),
       "rv64i2p1_f2p2_d2p2_v1p0_p0p21_zicsr2p0_zmmul1p0_zba1p0_zbb1p0_zve32f1p0_"
       "zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0");
+
+  auto MaybeRVY = RISCVISAInfo::parseArchString("rv64y0p910_m_a_f_d_c", true);
+  ASSERT_THAT_EXPECTED(MaybeRVY, Succeeded());
+  // The canonical string should place 'y' immediately after 'i' (before 'm').
+  EXPECT_EQ((*MaybeRVY)->toString(),
+            "rv64i2p1_y0p910_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zmmul1p0_"
+            "zaamo1p0_zalrsc1p0_zca1p0");
 }
 
 TEST(ParseArchString, RejectsUnrecognizedExtensionNamesByDefault) {
@@ -1004,10 +1011,10 @@ TEST(OrderedExtensionMap, ExtensionsAreCorrectlyOrdered) {
   for (const auto &Ext : Exts)
     ExtNames.push_back(Ext.first);
 
-  // FIXME: 'l' and 'y' should be ordered after 'i', 'm', 'c'.
+  // FIXME: 'l' should be ordered after 'i', 'm', 'c'.
   EXPECT_THAT(ExtNames,
-              ElementsAre("i", "m", "l", "c", "y", "zicsr", "zmfoo", "zfinx",
-                           "zzfoo", "sbar", "sfoo", "xbar", "xfoo"));
+              ElementsAre("i", "y", "m", "l", "c", "zicsr", "zmfoo", "zfinx",
+                          "zzfoo", "sbar", "sfoo", "xbar", "xfoo"));
 }
 
 TEST(ParseArchString, ZceImplication) {
@@ -1673,8 +1680,8 @@ R"(All available -march extensions for RISC-V
     xwchc                2.2
 
 Experimental extensions
-    p                    0.21
     y                    0.910
+    p                    0.21
     zibi                 0.1
     zicfilp              1.0       This is a long dummy description
     zilx                 0.1

``````````

</details>


https://github.com/llvm/llvm-project/pull/227865


More information about the llvm-commits mailing list