llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Kito Cheng (kito-cheng)

<details>
<summary>Changes</summary>

A riscv_rvv_vector_bits typedef of a data type keeps only the element type and 
count, and later stages re-derive the LMUL from VLEN. That breaks once typedefs 
may be shorter than VLEN * LMUL.

Split VectorKind::RVVFixedLengthData into RVVFixedLengthData_MF8 to _M8 and 
read the LMUL from the kind. VecKind grows to 5 bits.

This patch prepares to let a riscv_rvv_vector_bits typedef be shorter than VLEN 
* LMUL. It only records the LMUL and does not change any behavior.

Assisted-by: Claude

---

Patch is 25.55 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/237845.diff


11 Files Affected:

- (modified) clang/include/clang/AST/TypeBase.h (+93-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+4-4) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+16-16) 
- (modified) clang/lib/AST/JSONNodeDumper.cpp (+12-2) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+9-2) 
- (modified) clang/lib/AST/TypePrinter.cpp (+14-2) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+58-21) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaRISCV.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaType.cpp (+9-1) 
- (added) clang/test/AST/ast-dump-riscv-rvv-fixed-length-data-types.c (+40) 


``````````diff
diff --git a/clang/include/clang/AST/TypeBase.h 
b/clang/include/clang/AST/TypeBase.h
index 6373794bb69f54..09b381b512d0d4 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -2133,7 +2133,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
     /// The kind of vector, either a generic vector type or some
     /// target-specific vector type such as for AltiVec or Neon.
     LLVM_PREFERRED_TYPE(VectorKind)
-    unsigned VecKind : 4;
+    unsigned VecKind : 5;
     /// The number of elements in the vector.
     uint32_t NumElements;
   };
@@ -4255,7 +4255,13 @@ enum class VectorKind {
   SveFixedLengthPredicate,
 
   /// is RISC-V RVV fixed-length data vector
-  RVVFixedLengthData,
+  RVVFixedLengthData_MF8,
+  RVVFixedLengthData_MF4,
+  RVVFixedLengthData_MF2,
+  RVVFixedLengthData_M1,
+  RVVFixedLengthData_M2,
+  RVVFixedLengthData_M4,
+  RVVFixedLengthData_M8,
 
   /// is RISC-V RVV fixed-length mask vector
   RVVFixedLengthMask,
@@ -4265,6 +4271,91 @@ enum class VectorKind {
   RVVFixedLengthMask_4
 };
 
+/// True if \p VK is one of the RVV fixed-length data vector kinds, i.e. a
+/// riscv_rvv_vector_bits typedef of a data (non-mask) RVV type.
+inline bool isRVVFixedLengthDataVectorKind(VectorKind VK) {
+  switch (VK) {
+  case VectorKind::RVVFixedLengthData_MF8:
+  case VectorKind::RVVFixedLengthData_MF4:
+  case VectorKind::RVVFixedLengthData_MF2:
+  case VectorKind::RVVFixedLengthData_M1:
+  case VectorKind::RVVFixedLengthData_M2:
+  case VectorKind::RVVFixedLengthData_M4:
+  case VectorKind::RVVFixedLengthData_M8:
+    return true;
+  default:
+    return false;
+  }
+}
+
+/// Return log2 of the LMUL recorded in an RVV fixed-length data vector kind:
+/// MF8 -> -3, MF4 -> -2, MF2 -> -1, M1 -> 0, M2 -> 1, M4 -> 2, M8 -> 3.
+inline int getRVVFixedLengthDataLMulLog2(VectorKind VK) {
+  switch (VK) {
+  case VectorKind::RVVFixedLengthData_MF8:
+    return -3;
+  case VectorKind::RVVFixedLengthData_MF4:
+    return -2;
+  case VectorKind::RVVFixedLengthData_MF2:
+    return -1;
+  case VectorKind::RVVFixedLengthData_M1:
+    return 0;
+  case VectorKind::RVVFixedLengthData_M2:
+    return 1;
+  case VectorKind::RVVFixedLengthData_M4:
+    return 2;
+  case VectorKind::RVVFixedLengthData_M8:
+    return 3;
+  default:
+    llvm_unreachable("not an RVV fixed-length data vector kind");
+  }
+}
+
+/// Return the LMUL of an RVV fixed-length data vector kind as a string:
+/// "mf8" .. "m8" if \p MF is true, "1/8" .. "8" otherwise.
+inline StringRef getRVVFixedLengthDataLMulString(VectorKind VK, bool MF) {
+  switch (VK) {
+  case VectorKind::RVVFixedLengthData_MF8:
+    return MF ? "mf8" : "1/8";
+  case VectorKind::RVVFixedLengthData_MF4:
+    return MF ? "mf4" : "1/4";
+  case VectorKind::RVVFixedLengthData_MF2:
+    return MF ? "mf2" : "1/2";
+  case VectorKind::RVVFixedLengthData_M1:
+    return MF ? "m1" : "1";
+  case VectorKind::RVVFixedLengthData_M2:
+    return MF ? "m2" : "2";
+  case VectorKind::RVVFixedLengthData_M4:
+    return MF ? "m4" : "4";
+  case VectorKind::RVVFixedLengthData_M8:
+    return MF ? "m8" : "8";
+  default:
+    llvm_unreachable("not an RVV fixed-length data vector kind");
+  }
+}
+
+/// Inverse of getRVVFixedLengthDataLMulLog2().
+inline VectorKind getRVVFixedLengthDataVectorKind(int LMulLog2) {
+  switch (LMulLog2) {
+  case -3:
+    return VectorKind::RVVFixedLengthData_MF8;
+  case -2:
+    return VectorKind::RVVFixedLengthData_MF4;
+  case -1:
+    return VectorKind::RVVFixedLengthData_MF2;
+  case 0:
+    return VectorKind::RVVFixedLengthData_M1;
+  case 1:
+    return VectorKind::RVVFixedLengthData_M2;
+  case 2:
+    return VectorKind::RVVFixedLengthData_M4;
+  case 3:
+    return VectorKind::RVVFixedLengthData_M8;
+  default:
+    llvm_unreachable("LMUL out of range for an RVV type");
+  }
+}
+
 /// Represents a GCC generic vector type. This type is created using
 /// __attribute__((vector_size(n)), where "n" specifies the vector size in
 /// bytes; or from an Altivec __vector or vector declaration.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 01d71388cbc0e3..6afc80a2b908bb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2155,7 +2155,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
     else if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
       // Adjust the alignment for fixed-length SVE predicates.
       Align = 16;
-    else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
+    else if (isRVVFixedLengthDataVectorKind(VT->getVectorKind()) ||
              VT->getVectorKind() == VectorKind::RVVFixedLengthMask ||
              VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
              VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
@@ -10771,8 +10771,8 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
       First->getVectorKind() != VectorKind::SveFixedLengthPredicate &&
       Second->getVectorKind() != VectorKind::SveFixedLengthData &&
       Second->getVectorKind() != VectorKind::SveFixedLengthPredicate &&
-      First->getVectorKind() != VectorKind::RVVFixedLengthData &&
-      Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
+      !isRVVFixedLengthDataVectorKind(First->getVectorKind()) &&
+      !isRVVFixedLengthDataVectorKind(Second->getVectorKind()) &&
       First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
       Second->getVectorKind() != VectorKind::RVVFixedLengthMask &&
       First->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
@@ -10884,7 +10884,7 @@ bool ASTContext::areCompatibleRVVTypes(QualType 
FirstType,
                  Info.ElementType == BoolTy &&
                  getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)) * 2);
         }
-        if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
+        if (isRVVFixedLengthDataVectorKind(VT->getVectorKind()) ||
             VT->getVectorKind() == VectorKind::Generic)
           return FirstType->isRVVVLSBuiltinType() &&
                  getTypeSize(SecondType) == getRVVTypeSize(*this, BT) &&
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 02f27cec53f699..8fd9059abcdf3d 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4316,7 +4316,7 @@ void CXXNameMangler::mangleAArch64FixedSveVectorType(
 }
 
 void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
-  assert((T->getVectorKind() == VectorKind::RVVFixedLengthData ||
+  assert((isRVVFixedLengthDataVectorKind(T->getVectorKind()) ||
           T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
           T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
           T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
@@ -4335,7 +4335,7 @@ void CXXNameMangler::mangleRISCVFixedRVVVectorType(const 
VectorType *T) {
     TypeNameOS << "int8";
     break;
   case BuiltinType::UChar:
-    if (T->getVectorKind() == VectorKind::RVVFixedLengthData)
+    if (isRVVFixedLengthDataVectorKind(T->getVectorKind()))
       TypeNameOS << "uint8";
     else
       TypeNameOS << "bool";
@@ -4392,19 +4392,19 @@ void 
CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
     break;
   }
 
-  // Apend the LMUL suffix.
-  auto VScale = getASTContext().getTargetInfo().getVScaleRange(
-      getASTContext().getLangOpts(),
-      TargetInfo::ArmStreamingKind::NotStreaming);
-  unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
-
-  if (T->getVectorKind() == VectorKind::RVVFixedLengthData) {
-    TypeNameOS << 'm';
-    if (VecSizeInBits >= VLen)
-      TypeNameOS << (VecSizeInBits / VLen);
-    else
-      TypeNameOS << 'f' << (VLen / VecSizeInBits);
+  // Append the LMUL suffix. For data types the LMUL is recorded in the vector
+  // kind, so the mangled name names the type the typedef was written against
+  // even when the typedef is shorter than VLEN * LMUL, and does not depend on
+  // VLEN at all. Mask types are still tied to a fixed VLEN, so their ratio is
+  // derived from it.
+  if (isRVVFixedLengthDataVectorKind(T->getVectorKind())) {
+    TypeNameOS << getRVVFixedLengthDataLMulString(T->getVectorKind(),
+                                                  /*MF=*/true);
   } else {
+    auto VScale = getASTContext().getTargetInfo().getVScaleRange(
+        getASTContext().getLangOpts(),
+        TargetInfo::ArmStreamingKind::NotStreaming);
+    unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
     TypeNameOS << (VLen / VecSizeInBits);
   }
   TypeNameOS << "_t";
@@ -4445,7 +4445,7 @@ void CXXNameMangler::mangleType(const VectorType *T) {
              T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
     mangleAArch64FixedSveVectorType(T);
     return;
-  } else if (T->getVectorKind() == VectorKind::RVVFixedLengthData ||
+  } else if (isRVVFixedLengthDataVectorKind(T->getVectorKind()) ||
              T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
              T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
              T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
@@ -4478,7 +4478,7 @@ void CXXNameMangler::mangleType(const DependentVectorType 
*T) {
              T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
     mangleAArch64FixedSveVectorType(T);
     return;
-  } else if (T->getVectorKind() == VectorKind::RVVFixedLengthData) {
+  } else if (isRVVFixedLengthDataVectorKind(T->getVectorKind())) {
     mangleRISCVFixedRVVVectorType(T);
     return;
   }
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index 75abc4777f717f..2555c3658df02f 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -750,8 +750,18 @@ void JSONNodeDumper::VisitVectorType(const VectorType *VT) 
{
   case VectorKind::SveFixedLengthPredicate:
     JOS.attribute("vectorKind", "fixed-length sve predicate vector");
     break;
-  case VectorKind::RVVFixedLengthData:
-    JOS.attribute("vectorKind", "fixed-length rvv data vector");
+  case VectorKind::RVVFixedLengthData_MF8:
+  case VectorKind::RVVFixedLengthData_MF4:
+  case VectorKind::RVVFixedLengthData_MF2:
+  case VectorKind::RVVFixedLengthData_M1:
+  case VectorKind::RVVFixedLengthData_M2:
+  case VectorKind::RVVFixedLengthData_M4:
+  case VectorKind::RVVFixedLengthData_M8:
+    JOS.attribute("vectorKind",
+                  "fixed-length rvv data vector lmul " +
+                      getRVVFixedLengthDataLMulString(VT->getVectorKind(),
+                                                      /*MF=*/false)
+                          .str());
     break;
   case VectorKind::RVVFixedLengthMask:
   case VectorKind::RVVFixedLengthMask_1:
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 497fca228e428d..f1b216d970c731 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -2168,8 +2168,15 @@ void TextNodeDumper::VisitVectorType(const VectorType 
*T) {
   case VectorKind::SveFixedLengthPredicate:
     OS << " fixed-length sve predicate vector";
     break;
-  case VectorKind::RVVFixedLengthData:
-    OS << " fixed-length rvv data vector";
+  case VectorKind::RVVFixedLengthData_MF8:
+  case VectorKind::RVVFixedLengthData_MF4:
+  case VectorKind::RVVFixedLengthData_MF2:
+  case VectorKind::RVVFixedLengthData_M1:
+  case VectorKind::RVVFixedLengthData_M2:
+  case VectorKind::RVVFixedLengthData_M4:
+  case VectorKind::RVVFixedLengthData_M8:
+    OS << " fixed-length rvv data vector lmul "
+       << getRVVFixedLengthDataLMulString(T->getVectorKind(), /*MF=*/false);
     break;
   case VectorKind::RVVFixedLengthMask:
   case VectorKind::RVVFixedLengthMask_1:
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 13929f6fe08005..12cce9ccc32a55 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -718,7 +718,13 @@ void TypePrinter::printVectorBefore(const VectorType *T, 
raw_ostream &OS) {
     OS << ") * 8))) ";
     printBefore(T->getElementType(), OS);
     break;
-  case VectorKind::RVVFixedLengthData:
+  case VectorKind::RVVFixedLengthData_MF8:
+  case VectorKind::RVVFixedLengthData_MF4:
+  case VectorKind::RVVFixedLengthData_MF2:
+  case VectorKind::RVVFixedLengthData_M1:
+  case VectorKind::RVVFixedLengthData_M2:
+  case VectorKind::RVVFixedLengthData_M4:
+  case VectorKind::RVVFixedLengthData_M8:
   case VectorKind::RVVFixedLengthMask:
   case VectorKind::RVVFixedLengthMask_1:
   case VectorKind::RVVFixedLengthMask_2:
@@ -813,7 +819,13 @@ void TypePrinter::printDependentVectorBefore(
     OS << "))) ";
     printBefore(T->getElementType(), OS);
     break;
-  case VectorKind::RVVFixedLengthData:
+  case VectorKind::RVVFixedLengthData_MF8:
+  case VectorKind::RVVFixedLengthData_MF4:
+  case VectorKind::RVVFixedLengthData_MF2:
+  case VectorKind::RVVFixedLengthData_M1:
+  case VectorKind::RVVFixedLengthData_M2:
+  case VectorKind::RVVFixedLengthData_M4:
+  case VectorKind::RVVFixedLengthData_M8:
   case VectorKind::RVVFixedLengthMask:
   case VectorKind::RVVFixedLengthMask_1:
   case VectorKind::RVVFixedLengthMask_2:
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
index 4bac5711a2dd66..c84a4f00f4bc7f 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -40,6 +40,8 @@ class RISCVABIInfo : public DefaultABIInfo {
 
   llvm::Type *detectHomogeneousRVVFixedLengthStruct(QualType Ty) const;
 
+  unsigned getRVVFixedLengthMinElts(const VectorType *VT) const;
+
 public:
   RISCVABIInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen, unsigned FLen,
                bool EABI)
@@ -410,6 +412,35 @@ ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct(
   return ABIArgInfo::getCoerceAndExpand(CoerceToType, UnpaddedCoerceToType);
 }
 
+/// Minimum element count of the scalable vector an RVV fixed-length *data*
+/// vector is coerced to, i.e. the N in <vscale x N x T>. The LMUL comes from
+/// the vector kind - the type the typedef was written against - rather than
+/// from VLEN and the element count.
+static unsigned getRVVFixedLengthDataMinElts(VectorKind VK,
+                                             unsigned EltSizeInBits) {
+  // The underlying scalable type holds LMUL * RVVBitsPerBlock bits at
+  // vscale=1.
+  int LMulLog2 = getRVVFixedLengthDataLMulLog2(VK);
+  unsigned SizeAtVScale1 = LMulLog2 >= 0
+                               ? llvm::RISCV::RVVBitsPerBlock << LMulLog2
+                               : llvm::RISCV::RVVBitsPerBlock >> -LMulLog2;
+  assert(SizeAtVScale1 >= EltSizeInBits && "LMUL too small for element type");
+  return SizeAtVScale1 / EltSizeInBits;
+}
+
+/// Minimum element count of the scalable vector \p VT is coerced to, in units
+/// of \p VT's own Clang element type. Masks are modelled as i8 vectors and are
+/// exactly VLEN * LMUL wide, so their LMUL is recovered from VLEN.
+unsigned RISCVABIInfo::getRVVFixedLengthMinElts(const VectorType *VT) const {
+  unsigned EltSizeInBits = getContext().getTypeSize(VT->getElementType());
+  if (isRVVFixedLengthDataVectorKind(VT->getVectorKind()))
+    return getRVVFixedLengthDataMinElts(VT->getVectorKind(), EltSizeInBits);
+
+  auto VScale = getContext().getTargetInfo().getVScaleRange(
+      getContext().getLangOpts(), TargetInfo::ArmStreamingKind::NotStreaming);
+  return llvm::divideCeil(VT->getNumElements(), VScale->first);
+}
+
 llvm::Type *RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty,
                                                     unsigned ABIVLen) const {
   // No riscv_vls_cc attribute.
@@ -556,8 +587,9 @@ 
RISCVABIInfo::detectHomogeneousRVVFixedLengthStruct(QualType Ty) const {
     return nullptr;
 
   auto IsFixedLengthRVVVector = [](const VectorType *VT) {
+    if (isRVVFixedLengthDataVectorKind(VT->getVectorKind()))
+      return true;
     switch (VT->getVectorKind()) {
-    case VectorKind::RVVFixedLengthData:
     case VectorKind::RVVFixedLengthMask:
     case VectorKind::RVVFixedLengthMask_1:
     case VectorKind::RVVFixedLengthMask_2:
@@ -607,24 +639,21 @@ 
RISCVABIInfo::detectHomogeneousRVVFixedLengthStruct(QualType Ty) const {
 
   const auto *VT = CommonTy->castAs<VectorType>();
   llvm::Type *EltType = CGT.ConvertType(VT->getElementType());
-  auto VScale = getContext().getTargetInfo().getVScaleRange(
-      getContext().getLangOpts(), TargetInfo::ArmStreamingKind::NotStreaming);
-
-  // Ensure total register usage does not exceed 8.
-  if (Count > 1 &&
-      Count * llvm::divideCeil((uint64_t)VT->getNumElements() *
-                                   EltType->getScalarSizeInBits(),
-                               VScale->first * llvm::RISCV::RVVBitsPerBlock) >
-          8)
+  unsigned MinElts = getRVVFixedLengthMinElts(VT);
+
+  // Ensure total register usage does not exceed 8. Each vector occupies
+  // max(1, LMUL) registers.
+  uint64_t RegsPerVec =
+      llvm::divideCeil((uint64_t)MinElts * EltType->getScalarSizeInBits(),
+                       llvm::RISCV::RVVBitsPerBlock);
+  if (Count > 1 && Count * RegsPerVec > 8)
     return nullptr;
 
-  unsigned MinElts = llvm::divideCeil(VT->getNumElements(), VScale->first);
   if (Count == 1)
     return llvm::ScalableVectorType::get(EltType, MinElts);
 
-  unsigned I8EltCount = llvm::divideCeil((uint64_t)VT->getNumElements() *
-                                             EltType->getScalarSizeInBits(),
-                                         VScale->first * 8);
+  unsigned I8EltCount =
+      llvm::divideCeil((uint64_t)MinElts * EltType->getScalarSizeInBits(), 8);
   auto *I8Vec = llvm::ScalableVectorType::get(
       llvm::Type::getInt8Ty(getVMContext()), I8EltCount);
   return llvm::TargetExtType::get(getVMContext(), "riscv.vector.tuple", I8Vec,
@@ -675,7 +704,7 @@ ABIArgInfo RISCVABIInfo::coerceVLSVector(QualType Ty, 
unsigned ABIVLen) const {
     break;
   default:
     assert((VT->getVectorKind() == VectorKind::Generic ||
-            VT->getVectorKind() == VectorKind::RVVFixedLengthData) &&
+            isRVVFixedLengthDataVectorKind(VT->getVectorKind())) &&
            "Unexpected vector kind");
     EltType = CGT.ConvertType(VT->getElementType());
   }
@@ -683,11 +712,19 @@ ABIArgInfo RISCVABIInfo::coerceVLSVector(QualType Ty, 
unsigned ABIVLen) const {
   llvm::ScalableVectorType *ResType;
 
   if (ABIVLen == 0) {
-    // The MinNumElts is simplified from equation:
-    // NumElts / VScale =
-    //  (EltSize * NumElts / (VScale * RVVBitsPerBlock))
-    //    * (RVVBitsPerBlock / EltSize)
-    ResType = llvm::ScalableVectorType::get(EltType, NumElts / VScale->first);
+    unsigned MinScalableElts;
+    if (isRVVFixedLengthDataVectorKind(VT->getVectorKind())) {
+      // Use the LMUL of the type the typedef was written against.
+      MinScalableElts = getRVVFixedLengthDataMinElts(
+          VT->getVectorKind(), EltType->getScalarSizeInBits());
+    } else {
+      // The MinNumElts is simplified from equation:
+      // NumElts / VScale =
+      //  (EltSize * NumElts / (VScale * RVVBitsPerBlock))
+      //    * (RVVBitsPerBlock / EltSize)
+      MinScalableElts = NumElts / VScale->first;
+    }
+    ResType = llvm::ScalableVectorType::get(EltType, MinScalableElts);
   } else {
     // Check registers needed <= 8.
     if ((EltType->getScalarSizeInBits() * NumElts / ABIVLen) > 8)
@@ -824,7 +861,7 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, 
bool IsFixed,
   // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/419
   if (const VectorType *VT = Ty->getAs<VectorType>();
       VT && !VT->getElementType()->isBitIntType()) {
-    if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
+    if (isRVVFixedLengthDataVectorKind(VT->getVectorKind()) ||
         VT->getVectorKind() == VectorKind::RVVFixedLengthMask ||
         VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
         VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 00dd8acf1f68dd..9a11c859997eb6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11061,7 +11061,7 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, 
ExprResult &RHS,
       if (VecType->getVectorKind() == VectorKind::SveFixedLengthData ||
           VecType->getVectorKind() == VectorK...
[truncated]

``````````

</details>


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

Reply via email to