[clang] f3ce925 - [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 3 01:48:36 PDT 2023


Author: 4vtomat
Date: 2023-08-03T01:48:23-07:00
New Revision: f3ce925083d2214289c73b8f21590ac32beef03d

URL: https://github.com/llvm/llvm-project/commit/f3ce925083d2214289c73b8f21590ac32beef03d
DIFF: https://github.com/llvm/llvm-project/commit/f3ce925083d2214289c73b8f21590ac32beef03d.diff

LOG: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

This patch does a few things:
  1. Add a new type called Undefined to ScalarTypeKind.
  2. Make RVVType::applyModifier early return when encounter invalid
     ScalarType, otherwise it could be modified to "non-invalid" type in the following code.
  3. When FixedLMULType::SmallerThan is applied, the lmul should be "<" than
     specified one, so lmuls which are ">=" should be marked as invalid.

Differential Revision: https://reviews.llvm.org/D156223

Added: 
    clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c

Modified: 
    clang/include/clang/Support/RISCVVIntrinsicUtils.h
    clang/lib/Sema/SemaRISCVVectorLookup.cpp
    clang/lib/Support/RISCVVIntrinsicUtils.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 804b1518c06b51..e69df9ed720607 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -218,6 +218,7 @@ enum ScalarTypeKind : uint8_t {
   UnsignedInteger,
   Float,
   Invalid,
+  Undefined,
 };
 
 // Exponential LMUL
@@ -240,7 +241,7 @@ class RVVType {
   friend class RVVTypeCache;
 
   BasicType BT;
-  ScalarTypeKind ScalarType = Invalid;
+  ScalarTypeKind ScalarType = Undefined;
   LMULType LMUL;
   bool IsPointer = false;
   // IsConstant indices are "int", but have the constant expression.

diff  --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index db2059e68b3d17..eec2bc11e35d9e 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -133,6 +133,7 @@ static QualType RVVType2Qual(ASTContext &Context, const RVVType *Type) {
     }
     break;
   case Invalid:
+  case Undefined:
     llvm_unreachable("Unhandled type.");
   }
   if (Type->isVector()) {

diff  --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index 4b9736b6009ca9..abb4009ef2bce9 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -742,6 +742,10 @@ void RVVType::applyModifier(const PrototypeDescriptor &Transformer) {
     break;
   }
 
+  // Early return if the current type modifier is already invalid.
+  if (ScalarType == Invalid)
+    return;
+
   for (unsigned TypeModifierMaskShift = 0;
        TypeModifierMaskShift <= static_cast<unsigned>(TypeModifier::MaxOffset);
        ++TypeModifierMaskShift) {
@@ -803,13 +807,13 @@ void RVVType::applyFixedSEW(unsigned NewSEW) {
 void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
   switch (Type) {
   case FixedLMULType::LargerThan:
-    if (Log2LMUL < LMUL.Log2LMUL) {
+    if (Log2LMUL <= LMUL.Log2LMUL) {
       ScalarType = ScalarTypeKind::Invalid;
       return;
     }
     break;
   case FixedLMULType::SmallerThan:
-    if (Log2LMUL > LMUL.Log2LMUL) {
+    if (Log2LMUL >= LMUL.Log2LMUL) {
       ScalarType = ScalarTypeKind::Invalid;
       return;
     }

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
new file mode 100644
index 00000000000000..d00db214a69dcc
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
@@ -0,0 +1,21 @@
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zfh \
+// RUN:   -target-feature +zvfh -disable-O0-optnone %s -fsyntax-only -verify
+
+#include <riscv_vector.h>
+
+vuint64m2_t test_vlmul_trunc_v_u64m2_u64m2(vuint64m2_t op1) { // expected-note {{'test_vlmul_trunc_v_u64m2_u64m2' declared here}}
+  return __riscv_vlmul_trunc_v_u64m2_u64m2(op1); // expected-error {{call to undeclared function '__riscv_vlmul_trunc_v_u64m2_u64m2'; ISO C99 and later do not support implicit function declarations}} expected-error {{returning 'int' from a function with incompatible result type 'vuint64m2_t' (aka '__rvv_uint64m2_t')}} expected-note {{did you mean 'test_vlmul_trunc_v_u64m2_u64m2'?}}
+}
+
+vuint64m4_t test_vlmul_trunc_v_u64m4_u64m4(vuint64m4_t op1) { // expected-note {{'test_vlmul_trunc_v_u64m4_u64m4' declared here}}
+  return __riscv_vlmul_trunc_v_u64m4_u64m4(op1); // expected-error {{call to undeclared function '__riscv_vlmul_trunc_v_u64m4_u64m4'; ISO C99 and later do not support implicit function declarations}} expected-error {{returning 'int' from a function with incompatible result type 'vuint64m4_t' (aka '__rvv_uint64m4_t')}} expected-note {{did you mean 'test_vlmul_trunc_v_u64m4_u64m4'?}}
+}
+
+vuint64m1_t test_vlmul_trunc_v_u64m1_u64m1(vuint64m1_t op1) { // expected-note {{'test_vlmul_trunc_v_u64m1_u64m1' declared here}}
+  return __riscv_vlmul_trunc_v_u64m1_u64m1(op1); // expected-error {{call to undeclared function '__riscv_vlmul_trunc_v_u64m1_u64m1'; ISO C99 and later do not support implicit function declarations}} expected-error {{returning 'int' from a function with incompatible result type 'vuint64m1_t' (aka '__rvv_uint64m1_t')}} expected-note {{did you mean 'test_vlmul_trunc_v_u64m1_u64m1'?}}
+}
+
+vuint64m8_t test_vlmul_trunc_v_u64m8_u64m8(vuint64m8_t op1) { // expected-note {{'test_vlmul_trunc_v_u64m8_u64m8' declared here}}
+  return __riscv_vlmul_trunc_v_u64m8_u64m8(op1); // expected-error {{call to undeclared function '__riscv_vlmul_trunc_v_u64m8_u64m8'; ISO C99 and later do not support implicit function declarations}} expected-error {{returning 'int' from a function with incompatible result type 'vuint64m8_t' (aka '__rvv_uint64m8_t')}} expected-note {{did you mean 'test_vlmul_trunc_v_u64m8_u64m8'?}}
+}


        


More information about the cfe-commits mailing list