https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/186993

zvknhb now implies zvknha so we dont need to check extensions manually
in SemaRISCV, we can just use RequiredFeatures instead.


>From 587ce0ecc2b5de47d71ecbed405e97dd2fd8b77a Mon Sep 17 00:00:00 2001
From: Brandon Wu <[email protected]>
Date: Tue, 17 Mar 2026 03:33:59 -0700
Subject: [PATCH] [clang][RISCV] Add RequiredFeatures for zvknha and zvknhb

zvknhb now implies zvknha so we dont need to check extensions manually
in SemaRISCV, we can just use RequiredFeatures instead.
---
 clang/include/clang/Basic/riscv_vector.td | 18 +++++++++++++-----
 clang/lib/Sema/SemaRISCV.cpp              | 12 ------------
 clang/test/Sema/zvk-invalid-features.c    | 15 ++++++++++-----
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 6d45e6ca94cd1..5e4edbe01f1cd 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2080,11 +2080,19 @@ let UnMaskedPolicyScheme = HasPolicyOperand, HasMasked 
= false in {
     defm vaesz   : RVVOutBuiltinSetZvk<HasVV=0>;
   }
 
-  // zvknha and zvknhb has duplicated intrinsic but they don't imply each 
other,
-  // so we need to handle it manually in SemaRISCV.cpp.
-  defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"il">;
-  defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"il">;
-  defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"il">;
+  // zvknha
+  let RequiredFeatures = ["zvknha"] in {
+    defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"i">;
+    defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"i">;
+    defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"i">;
+  }
+
+  // zvknhb
+  let RequiredFeatures = ["zvknhb"] in {
+    defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"l">;
+    defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"l">;
+    defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"l">;
+  }
 
   // zvksed
   let RequiredFeatures = ["zvksed"] in {
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index d5512f216ddb3..3cf5a0963b39c 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -839,18 +839,6 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
     ASTContext::BuiltinVectorTypeInfo Info =
         Context.getBuiltinVectorTypeInfo(Arg0Type->castAs<BuiltinType>());
     uint64_t ElemSize = Context.getTypeSize(Info.ElementType);
-    if (ElemSize == 64 && !TI.hasFeature("zvknhb") &&
-        !FunctionFeatureMap.lookup("zvknhb"))
-      return Diag(TheCall->getBeginLoc(),
-                  diag::err_riscv_builtin_requires_extension)
-             << /* IsExtension */ true << TheCall->getSourceRange() << 
"zvknhb";
-    // If ElemSize is 32, check at least zvknha or zvknhb is enabled.
-    if (!TI.hasFeature("zvknha") && !FunctionFeatureMap.lookup("zvknha") &&
-        !TI.hasFeature("zvknhb") && !FunctionFeatureMap.lookup("zvknhb"))
-      return Diag(TheCall->getBeginLoc(),
-                  diag::err_riscv_builtin_requires_extension)
-             << /* IsExtension */ true << TheCall->getSourceRange()
-             << "zvknha or zvknhb";
 
     return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
                                    Arg0Type, ElemSize * 4) ||
diff --git a/clang/test/Sema/zvk-invalid-features.c 
b/clang/test/Sema/zvk-invalid-features.c
index 4b666b4480f73..4c51e1547f828 100644
--- a/clang/test/Sema/zvk-invalid-features.c
+++ b/clang/test/Sema/zvk-invalid-features.c
@@ -3,7 +3,7 @@
 
 #include <riscv_vector.h>
 
-void test_zvk_features(vuint32m4_t vd, vuint32m4_t vs2, vuint32m4_t vs1, 
vuint64m1_t vs2_64, vuint64m1_t vs1_64, size_t vl) {
+void test_zvk_features(vuint32m4_t vd, vuint32m4_t vs2, vuint32m4_t vs1, 
vuint64m1_t vd_64, vuint64m1_t vs2_64, vuint64m1_t vs1_64, size_t vl) {
   // zvbb
   __riscv_vbrev(vs2, vl); // expected-error {{builtin requires at least one of 
the following extensions: zvbb}}
   __riscv_vclz(vs2, vl); // expected-error {{builtin requires at least one of 
the following extensions: zvbb}}
@@ -35,10 +35,15 @@ void test_zvk_features(vuint32m4_t vd, vuint32m4_t vs2, 
vuint32m4_t vs1, vuint64
   __riscv_vaeskf2(vd, vs2, 0, vl); // expected-error {{builtin requires at 
least one of the following extensions: zvkned}}
   __riscv_vaesz(vd, vs2, vl); // expected-error {{builtin requires at least 
one of the following extensions: zvkned}}
 
-  // zvknha or zvknhb
-  __riscv_vsha2ch(vd, vs2, vs1, vl); // expected-error {{builtin requires at 
least one of the following extensions: zvknha or zvknhb}}
-  __riscv_vsha2cl(vd, vs2, vs1, vl); // expected-error {{builtin requires at 
least one of the following extensions: zvknha or zvknhb}}
-  __riscv_vsha2ms(vd, vs2, vs1, vl); // expected-error {{builtin requires at 
least one of the following extensions: zvknha or zvknhb}}
+  // zvknha
+  __riscv_vsha2ch(vd, vs2, vs1, vl); // expected-error {{builtin requires at 
least one of the following extensions: zvknha}}
+  __riscv_vsha2cl(vd, vs2, vs1, vl); // expected-error {{builtin requires at 
least one of the following extensions: zvknha}}
+  __riscv_vsha2ms(vd, vs2, vs1, vl); // expected-error {{builtin requires at 
least one of the following extensions: zvknha}}
+
+  // zvknhb
+  __riscv_vsha2ch(vd_64, vs2_64, vs1_64, vl); // expected-error {{builtin 
requires at least one of the following extensions: zvknhb}}
+  __riscv_vsha2cl(vd_64, vs2_64, vs1_64, vl); // expected-error {{builtin 
requires at least one of the following extensions: zvknhb}}
+  __riscv_vsha2ms(vd_64, vs2_64, vs1_64, vl); // expected-error {{builtin 
requires at least one of the following extensions: zvknhb}}
 
   //zvksed
   __riscv_vsm4k(vs2, 0, vl); // expected-error {{builtin requires at least one 
of the following extensions: zvksed}}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to