[llvm-branch-commits] [clang] [Clang][RISCV] Allow riscv_rvv_vector_bits typedefs shorter than VLEN*LMUL (PR #237846)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 1 22:16:17 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Kito Cheng (kito-cheng)

<details>
<summary>Changes</summary>

`riscv_rvv_vector_bits(N)` on a data type now accepts any N up to VLEN * LMUL that gives a power-of-2 number of elements. Without -mrvv-vector-bits=, VLEN is the minimum VLEN from -march.

A shorter typedef keeps the LMUL of its sizeless type and uses only the low lanes. It converts implicitly to and from that sizeless type only.

Mask types are unchanged, that would be follow up PR for easier review.

Assisted-by: Claude

---

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


14 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+6) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+16-7) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+9) 
- (modified) clang/lib/AST/ASTContext.cpp (+25-5) 
- (modified) clang/lib/Sema/SemaType.cpp (+38-12) 
- (added) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-lmul.c (+180) 
- (added) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-no-flag.c (+40) 
- (added) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-relaxed-call.c (+50) 
- (added) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-relaxed-convert.c (+94) 
- (added) clang/test/CodeGenCXX/riscv-mangle-rvv-fixed-vectors-lmul.cpp (+39) 
- (modified) clang/test/Driver/riscv-rvv-vector-bits.c (+9-6) 
- (added) clang/test/Sema/attr-riscv-rvv-vector-bits-lmul.c (+125) 
- (added) clang/test/Sema/attr-riscv-rvv-vector-bits-no-flag.c (+80) 
- (added) clang/test/Sema/attr-riscv-rvv-vector-bits-relaxed.c (+67) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index a367196a601bc7..ed34bed7df8604 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1327,6 +1327,12 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
   `-mcpu` is present, the ISA will be selected from the host CPU and the tune
   CPU will be selected from `-mcpu`.
 
+- `riscv_rvv_vector_bits(N)` now accepts any `N` up to `VLEN*LMUL` bits for
+  data types. For them it no longer requires `-mrvv-vector-bits`; without it,
+  `VLEN` is the minimum required by `-march`. A shorter typedef keeps the LMUL
+  of the type it was written against, and converts implicitly to and from that
+  sizeless type (truncating, or leaving the upper lanes undefined).
+
 #### CUDA/HIP Language Changes
 
 - HIP compilations now add the `include/libhipcxx` directory from the selected
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 687e022c7bd61f..89b8b86f3b9ed9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3347,15 +3347,24 @@ can be used in globals, structs, unions, and arrays, all of which are
 unsupported for sizeless types.
 
 The attribute can be attached to a single RVV vector (such as `vint8m1_t`).
-The attribute will be rejected unless
-`N==(__riscv_v_fixed_vlen*LMUL)`, the implementation defined feature macro that
-is enabled under the `-mrvv-vector-bits` flag. `__riscv_v_fixed_vlen` can
-only be a power of 2 between 64 and 65536.
 
-For types where LMUL!=1, `__riscv_v_fixed_vlen` needs to be scaled by the LMUL
-of the type before passing to the attribute.
+For data types, `N` is a size in bits. It must be a positive multiple of the
+element size, `N` divided by the element size must be a power of 2, and `N`
+must not exceed `VLEN*LMUL`.
 
-For `vbool*_t` types, `__riscv_v_fixed_vlen` needs to be divided by the
+A data type with `N` smaller than `VLEN*LMUL` uses only the low lanes of the
+register group:
+
+- It keeps the LMUL of the type it was written against. For example,
+  `vint32m1_t` with `riscv_rvv_vector_bits(64)` occupies one vector register
+  and is a different type from `vint32mf2_t` with `riscv_rvv_vector_bits(64)`.
+- It converts implicitly to and from its own sizeless type only. Converting to
+  the sizeless type leaves the upper lanes undefined; converting back keeps the
+  first `N` bits. When such a value is passed to an RVV intrinsic, the
+  programmer must keep `vl` (and any `vrgather` index) within those lanes.
+
+For `vbool*_t` types, the attribute will be rejected unless
+`-mrvv-vector-bits` is given and `N` is `__riscv_v_fixed_vlen` divided by the
 number from the type name. For example, `vbool8_t` needs to use
 `__riscv_v_fixed_vlen` / 8. If the resulting value is not a multiple of 8,
 the type is not supported for that value of `__riscv_v_fixed_vlen`.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 56cc9721781063..bbebbb37a3ce24 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3457,6 +3457,15 @@ def err_attribute_riscv_rvv_bits_unsupported : Error<
 def err_attribute_bad_rvv_vector_size : Error<
   "invalid RVV vector size '%0', expected size is '%1' based on LMUL of type "
   "and '-mrvv-vector-bits'">;
+def err_attribute_bad_rvv_vector_size_too_large : Error<
+  "invalid RVV vector size '%0', must not exceed '%1' based on LMUL of type "
+  "and the minimum VLEN">;
+def err_attribute_bad_rvv_vector_size_not_multiple_of_elem : Error<
+  "invalid RVV vector size '%0', must be a positive multiple of the element "
+  "size '%1'">;
+def err_attribute_bad_rvv_vector_size_not_pow2 : Error<
+  "invalid RVV vector size '%0', the resulting element count '%1' must be a "
+  "power of 2">;
 def err_attribute_invalid_rvv_type : Error<
   "%0 attribute applied to non-RVV type %1">;
 def err_attribute_requires_positive_integer : Error<
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 6afc80a2b908bb..c821fb50d3b0f2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -91,6 +91,7 @@
 #include "llvm/Support/SipHash.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include <algorithm>
 #include <cassert>
@@ -10850,6 +10851,16 @@ static uint64_t getRVVTypeSize(ASTContext &Context, const BuiltinType *Ty) {
   return VScale->first * MinElts * EltSize;
 }
 
+/// Return log2 of the LMUL of a sizeless RVV data type, as
+/// getRVVFixedLengthDataLMulLog2() does for a vector kind.
+static int getRVVBuiltinLMulLog2(ASTContext &Context, const BuiltinType *Ty) {
+  ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo(Ty);
+  uint64_t SizeAtVScale1 =
+      Info.EC.getKnownMinValue() * Context.getTypeSize(Info.ElementType);
+  return int(llvm::Log2_64(SizeAtVScale1)) -
+         int(llvm::Log2_32(llvm::RISCV::RVVBitsPerBlock));
+}
+
 bool ASTContext::areCompatibleRVVTypes(QualType FirstType,
                                        QualType SecondType) {
   assert(
@@ -10885,11 +10896,20 @@ bool ASTContext::areCompatibleRVVTypes(QualType FirstType,
                  getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)) * 2);
         }
         if (isRVVFixedLengthDataVectorKind(VT->getVectorKind()) ||
-            VT->getVectorKind() == VectorKind::Generic)
-          return FirstType->isRVVVLSBuiltinType() &&
-                 getTypeSize(SecondType) == getRVVTypeSize(*this, BT) &&
-                 hasSameType(VT->getElementType(),
-                             getBuiltinVectorTypeInfo(BT).ElementType);
+            VT->getVectorKind() == VectorKind::Generic) {
+          bool IsRVVFixed = isRVVFixedLengthDataVectorKind(VT->getVectorKind());
+          BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+          // A riscv_rvv_vector_bits typedef may be shorter than the sizeless
+          // type, but must have the same LMUL.
+          bool SizeOk =
+              IsRVVFixed ? getTypeSize(SecondType) <= getRVVTypeSize(*this, BT)
+                         : getTypeSize(SecondType) == getRVVTypeSize(*this, BT);
+          bool LMulOk = !IsRVVFixed || Info.ElementType == BoolTy ||
+                        getRVVFixedLengthDataLMulLog2(VT->getVectorKind()) ==
+                            getRVVBuiltinLMulLog2(*this, BT);
+          return FirstType->isRVVVLSBuiltinType() && SizeOk && LMulOk &&
+                 hasSameType(VT->getElementType(), Info.ElementType);
+        }
       }
     }
     return false;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 9c299b9e55da8d..f6137dd75f86fa 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8843,15 +8843,6 @@ static void HandleRISCVRVVVectorBitsTypeAttr(QualType &CurType,
     return;
   }
 
-  auto VScale = S.Context.getTargetInfo().getVScaleRange(
-      S.getLangOpts(), TargetInfo::ArmStreamingKind::NotStreaming);
-  if (!VScale || !VScale->first || VScale->first != VScale->second) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_riscv_rvv_bits_unsupported)
-        << Attr;
-    Attr.setInvalid();
-    return;
-  }
-
   // The vector size must be an integer constant expression.
   llvm::APSInt RVVVectorSizeInBits(32);
   if (!verifyValidIntegerConstantExpr(S, Attr, RVVVectorSizeInBits))
@@ -8870,13 +8861,25 @@ static void HandleRISCVRVVVectorBitsTypeAttr(QualType &CurType,
   ASTContext::BuiltinVectorTypeInfo Info =
       S.Context.getBuiltinVectorTypeInfo(CurType->castAs<BuiltinType>());
   unsigned MinElts = Info.EC.getKnownMinValue();
+  bool IsMask = Info.ElementType == S.Context.BoolTy;
+
+  // A data type needs only the minimum VLEN; a mask type needs a fixed VLEN.
+  auto VScale = S.Context.getTargetInfo().getVScaleRange(
+      S.getLangOpts(), TargetInfo::ArmStreamingKind::NotStreaming);
+  if (!VScale || !VScale->first ||
+      (IsMask && VScale->first != VScale->second)) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_riscv_rvv_bits_unsupported)
+        << Attr;
+    Attr.setInvalid();
+    return;
+  }
 
   VectorKind VecKind = VectorKind::RVVFixedLengthMask;
   unsigned ExpectedSize = VScale->first * MinElts;
   QualType EltType = CurType->getRVVEltType(S.Context);
   unsigned EltSize = S.Context.getTypeSize(EltType);
   unsigned NumElts;
-  if (Info.ElementType == S.Context.BoolTy) {
+  if (IsMask) {
     NumElts = VecSize / S.Context.getCharWidth();
     if (!NumElts) {
       NumElts = 1;
@@ -8905,14 +8908,37 @@ static void HandleRISCVRVVVectorBitsTypeAttr(QualType &CurType,
         int(llvm::Log2_32(llvm::RISCV::RVVBitsPerBlock)));
   }
 
-  // The attribute vector size must match -mrvv-vector-bits.
-  if (VecSize != ExpectedSize) {
+  // The size of a mask type must match -mrvv-vector-bits.
+  if (IsMask && VecSize != ExpectedSize) {
     S.Diag(Attr.getLoc(), diag::err_attribute_bad_rvv_vector_size)
         << VecSize << ExpectedSize;
     Attr.setInvalid();
     return;
   }
 
+  // A data type may be shorter than VLEN * LMUL, with a power-of-2 number of
+  // elements.
+  if (VecSize > ExpectedSize) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_bad_rvv_vector_size_too_large)
+        << VecSize << ExpectedSize;
+    Attr.setInvalid();
+    return;
+  }
+  if (!IsMask && (VecSize == 0 || (VecSize % EltSize) != 0)) {
+    S.Diag(Attr.getLoc(),
+           diag::err_attribute_bad_rvv_vector_size_not_multiple_of_elem)
+        << VecSize << EltSize;
+    Attr.setInvalid();
+    return;
+  }
+  unsigned NumLanes = IsMask ? VecSize : NumElts;
+  if (!llvm::isPowerOf2_32(NumLanes)) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_bad_rvv_vector_size_not_pow2)
+        << VecSize << NumLanes;
+    Attr.setInvalid();
+    return;
+  }
+
   CurType = S.Context.getVectorType(EltType, NumElts, VecKind);
 }
 
diff --git a/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-lmul.c b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-lmul.c
new file mode 100644
index 00000000000000..d851acc974a466
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-lmul.c
@@ -0,0 +1,180 @@
+// Verify that a riscv_rvv_vector_bits typedef keeps the LMUL of the sizeless
+// RVV type it was written against, rather than having it re-derived from VLEN
+// and the declared lane count.
+//
+// A typedef may declare fewer lanes than
+// VLEN * LMUL, so NumElements / vscale under-estimates the LMUL. Two typedefs
+// with the same element type and lane count but different LMULs must map to
+// different scalable vector types.
+//
+// VLEN=128 (vscale=2): vint32mf2_t holds 2 i32 lanes at full size,
+// vint32m1_t 4, vint32m2_t 8, vint32m4_t 16.
+
+// RUN: %clang_cc1 -triple riscv64-none-linux-gnu \
+// RUN:   -target-feature +f -target-feature +d -target-feature +zve64d \
+// RUN:   -mvscale-min=2 -mvscale-max=2 \
+// RUN:   -O1 -emit-llvm -o - %s | FileCheck %s
+
+// REQUIRES: riscv-registered-target
+
+#include <riscv_vector.h>
+
+// All of these hold 2 i32 lanes; only the LMUL differs.
+typedef vint32mf2_t mf2_64 __attribute__((riscv_rvv_vector_bits(64)));
+typedef vint32m1_t  m1_64  __attribute__((riscv_rvv_vector_bits(64)));
+typedef vint32m2_t  m2_64  __attribute__((riscv_rvv_vector_bits(64)));
+typedef vint32m4_t  m4_64  __attribute__((riscv_rvv_vector_bits(64)));
+
+// A single lane out of an LMUL=1 group.
+typedef vint32m1_t m1_32 __attribute__((riscv_rvv_vector_bits(32)));
+
+// Other element sizes.
+typedef vint8m1_t    i8m1_32   __attribute__((riscv_rvv_vector_bits(32)));
+typedef vint8mf4_t   i8mf4_16  __attribute__((riscv_rvv_vector_bits(16)));
+typedef vfloat32m1_t f32m1_64  __attribute__((riscv_rvv_vector_bits(64)));
+typedef vfloat64m1_t f64m1_64  __attribute__((riscv_rvv_vector_bits(64)));
+
+//===----------------------------------------------------------------------===//
+// Same lane count, different LMUL => different ABI types.
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: define dso_local noundef <vscale x 1 x i32> @id_mf2_64(
+// CHECK-SAME:    <vscale x 1 x i32> {{.*}}%x.coerce)
+mf2_64 id_mf2_64(mf2_64 x) { return x; }
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x i32> @id_m1_64(
+// CHECK-SAME:    <vscale x 2 x i32> {{.*}}%x.coerce)
+m1_64 id_m1_64(m1_64 x) { return x; }
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 4 x i32> @id_m2_64(
+// CHECK-SAME:    <vscale x 4 x i32> {{.*}}%x.coerce)
+m2_64 id_m2_64(m2_64 x) { return x; }
+
+// Two lanes of an LMUL=4 type still occupy the whole LMUL=4 group.
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 8 x i32> @id_m4_64(
+// CHECK-SAME:    <vscale x 8 x i32> {{.*}}%x.coerce)
+m4_64 id_m4_64(m4_64 x) { return x; }
+
+// One lane still occupies a whole LMUL=1 group.
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x i32> @id_m1_32(
+// CHECK-SAME:    <vscale x 2 x i32> {{.*}}%x.coerce)
+m1_32 id_m1_32(m1_32 x) { return x; }
+
+//===----------------------------------------------------------------------===//
+// Other element sizes.
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 8 x i8> @id_i8m1_32(
+// CHECK-SAME:    <vscale x 8 x i8> {{.*}}%x.coerce)
+i8m1_32 id_i8m1_32(i8m1_32 x) { return x; }
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x i8> @id_i8mf4_16(
+// CHECK-SAME:    <vscale x 2 x i8> {{.*}}%x.coerce)
+i8mf4_16 id_i8mf4_16(i8mf4_16 x) { return x; }
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x float> @id_f32m1_64(
+// CHECK-SAME:    <vscale x 2 x float> {{.*}}%x.coerce)
+f32m1_64 id_f32m1_64(f32m1_64 x) { return x; }
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 1 x double> @id_f64m1_64(
+// CHECK-SAME:    <vscale x 1 x double> {{.*}}%x.coerce)
+f64m1_64 id_f64m1_64(f64m1_64 x) { return x; }
+
+//===----------------------------------------------------------------------===//
+// Calling RVV intrinsics with these typedefs. Because the ABI type already
+// matches the LMUL the intrinsic expects, the argument flows straight into the
+// intrinsic with no llvm.vector.insert / llvm.vector.extract in between.
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x i32> @add_m1(
+// CHECK-SAME:    <vscale x 2 x i32> {{.*}}%a.coerce, <vscale x 2 x i32> {{.*}}%b.coerce)
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[R:%.*]] = {{.*}}call <vscale x 2 x i32> @llvm.riscv.vadd.nxv2i32.nxv2i32.i64(<vscale x 2 x i32> poison, <vscale x 2 x i32> %a.coerce, <vscale x 2 x i32> %b.coerce, i64 2)
+// CHECK-NEXT:    ret <vscale x 2 x i32> [[R]]
+m1_64 add_m1(m1_64 a, m1_64 b) { return __riscv_vadd_vv_i32m1(a, b, 2); }
+
+// Same lane count as add_m1, but the mf2 typedef selects the mf2 intrinsic.
+// CHECK-LABEL: define dso_local <vscale x 1 x i32> @add_mf2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[R:%.*]] = {{.*}}call <vscale x 1 x i32> @llvm.riscv.vadd.nxv1i32.nxv1i32.i64(<vscale x 1 x i32> poison, <vscale x 1 x i32> %a.coerce, <vscale x 1 x i32> %b.coerce, i64 2)
+// CHECK-NEXT:    ret <vscale x 1 x i32> [[R]]
+mf2_64 add_mf2(mf2_64 a, mf2_64 b) { return __riscv_vadd_vv_i32mf2(a, b, 2); }
+
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 4 x i32> @add_m2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[R:%.*]] = {{.*}}call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32.i64(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a.coerce, <vscale x 4 x i32> %b.coerce, i64 2)
+// CHECK-NEXT:    ret <vscale x 4 x i32> [[R]]
+m2_64 add_m2(m2_64 a, m2_64 b) { return __riscv_vadd_vv_i32m2(a, b, 2); }
+
+// Fractional LMUL with a narrow element type.
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x i8> @add_i8mf4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[R:%.*]] = {{.*}}call <vscale x 2 x i8> @llvm.riscv.vadd.nxv2i8.nxv2i8.i64(<vscale x 2 x i8> poison, <vscale x 2 x i8> %a.coerce, <vscale x 2 x i8> %b.coerce, i64 2)
+// CHECK-NEXT:    ret <vscale x 2 x i8> [[R]]
+i8mf4_16 add_i8mf4(i8mf4_16 a, i8mf4_16 b) {
+  return __riscv_vadd_vv_i8mf4(a, b, 2);
+}
+
+// Floating point.
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x float> @fadd_m1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[R:%.*]] = {{.*}}call <vscale x 2 x float> @llvm.riscv.vfadd.nxv2f32.nxv2f32.i64(<vscale x 2 x float> poison, <vscale x 2 x float> %a.coerce, <vscale x 2 x float> %b.coerce, i64 7, i64 2)
+// CHECK-NEXT:    ret <vscale x 2 x float> [[R]]
+f32m1_64 fadd_m1(f32m1_64 a, f32m1_64 b) {
+  return __riscv_vfadd_vv_f32m1(a, b, 2);
+}
+
+// Load returning into the shorter typedef.
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x i32> @load_m1(
+// CHECK:         [[R:%.*]] = {{.*}}call <vscale x 2 x i32> @llvm.riscv.vle.nxv2i32.p0.i64(<vscale x 2 x i32> poison, ptr %p, i64 2)
+// CHECK-NEXT:    ret <vscale x 2 x i32> [[R]]
+m1_64 load_m1(const int *p) { return __riscv_vle32_v_i32m1(p, 2); }
+
+// Store taking the shorter typedef.
+// CHECK-LABEL: define dso_local void @store_m1(
+// CHECK:         call void @llvm.riscv.vse.nxv2i32.p0.i64(<vscale x 2 x i32> %v.coerce, ptr %p, i64 2)
+void store_m1(int *p, m1_64 v) { __riscv_vse32_v_i32m1(p, v, 2); }
+
+// Mask-producing and masked intrinsics: the mask LMUL follows the data LMUL.
+// CHECK-LABEL: define dso_local {{.*}}<vscale x 2 x i32> @masked_add_m1(
+// CHECK:         [[M:%.*]] = {{.*}}call <vscale x 2 x i1> @llvm.riscv.vmseq.nxv2i32.nxv2i32.i64(<vscale x 2 x i32> %a.coerce, <vscale x 2 x i32> %b.coerce, i64 2)
+// CHECK-NEXT:    [[R:%.*]] = {{.*}}call <vscale x 2 x i32> @llvm.riscv.vadd.mask.nxv2i32.nxv2i32.i64(<vscale x 2 x i32> poison, <vscale x 2 x i32> %a.coerce, <vscale x 2 x i32> %b.coerce, <vscale x 2 x i1> [[M]], i64 2, i64 3)
+// CHECK-NEXT:    ret <vscale x 2 x i32> [[R]]
+m1_64 masked_add_m1(m1_64 a, m1_64 b) {
+  vbool32_t m = __riscv_vmseq_vv_i32m1_b32(a, b, 2);
+  return __riscv_vadd_vv_i32m1_m(m, a, b, 2);
+}
+
+//===----------------------------------------------------------------------===//
+// Structs. The number of vector registers a field needs follows its LMUL, not
+// the number of lanes it declares.
+//===----------------------------------------------------------------------===//
+
+struct s1_m1 { m1_64 a; };
+// CHECK-LABEL: define dso_local void @st1_m1(
+// CHECK-SAME:    <vscale x 2 x i32>
+void st1_m1(struct s1_m1 s) {}
+
+struct s2_m1 { m1_64 a, b; };
+// CHECK-LABEL: define dso_local void @st2_m1(
+// CHECK-SAME:    target("riscv.vector.tuple", <vscale x 8 x i8>, 2)
+void st2_m1(struct s2_m1 s) {}
+
+struct s2_mf2 { mf2_64 a, b; };
+// CHECK-LABEL: define dso_local void @st2_mf2(
+// CHECK-SAME:    target("riscv.vector.tuple", <vscale x 4 x i8>, 2)
+void st2_mf2(struct s2_mf2 s) {}
+
+// 2 * LMUL4 = 8 registers, right at the limit.
+struct s2_m4 { m4_64 a, b; };
+// CHECK-LABEL: define dso_local void @st2_m4(
+// CHECK-SAME:    target("riscv.vector.tuple", <vscale x 32 x i8>, 2)
+void st2_m4(struct s2_m4 s) {}
+
+// 3 * LMUL4 = 12 registers, over the limit, so the struct is passed
+// indirectly. Deriving the LMUL from the lane count would have made this look
+// like 3 * LMUL(1/2) and wrongly passed it in registers.
+struct s3_m4 { m4_64 a, b, c; };
+// CHECK-LABEL: define dso_local void @st3_m4(
+// CHECK-SAME:    ptr
+void st3_m4(struct s3_m4 s) {}
diff --git a/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-no-flag.c b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-no-flag.c
new file mode 100644
index 00000000000000..eab187b70b2214
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/attr-rvv-vector-bits-no-flag.c
@@ -0,0 +1,40 @@
+// Verify that riscv_rvv_vector_bits typedefs work without -mrvv-vector-bits=,
+// using only the ISA's Zvl*b extension as the lower bound. The fixed<->scalable
+// conversion IR landmarks must be present.
+
+// zvl128b, no -mrvv-vector-bits=:
+// RUN: %clang_cc1 -triple riscv64-none-linux-gnu \
+// RUN:   -target-feature +f -target-feature +d -target-feature +zve64d \
+// RUN:   -target-feature +zvl128b \
+// RUN:   -O1 -emit-llvm -o - %s | FileCheck %s
+
+// The fixed<->scalable conversions fold away at -O1 now that both sides use
+// the same LMUL, so check the landmarks on unoptimized IR.
+// RUN: %clang_cc1 -triple ...
[truncated]

``````````

</details>


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


More information about the llvm-branch-commits mailing list