Skip to content

Commit 33af2f1

Browse files
committed
[RISCV] Check type size for lax conversions between RVV builtin types and VectorType::RVVFixedLengthDataVector.
This code was copied from SVE and modified for RVV. For SVE, there is only one size for builtin types so they didn't need to check the size. For RVV, due to LMUL there are 7 different sizes of builtin types so we do need to check the size. I'm not sure we should have lax vector conversions at all for RVV. That appears to be contributing to llvm#64404 This patch at least fixes the obvious correctness issue. This should be backported to LLVM 17. Reviewed By: jacquesguan Differential Revision: https://reviews.llvm.org/D157130
1 parent 86ed8cb commit 33af2f1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

clang/lib/AST/ASTContext.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -9612,9 +9612,8 @@ bool ASTContext::areLaxCompatibleRVVTypes(QualType FirstType,
96129612
const LangOptions::LaxVectorConversionKind LVCKind =
96139613
getLangOpts().getLaxVectorConversions();
96149614

9615-
// If __riscv_v_fixed_vlen != N do not allow GNU vector lax conversion.
9616-
if (VecTy->getVectorKind() == VectorType::GenericVector &&
9617-
getTypeSize(SecondType) != getRVVTypeSize(*this, BT))
9615+
// If __riscv_v_fixed_vlen != N do not allow vector lax conversion.
9616+
if (getTypeSize(SecondType) != getRVVTypeSize(*this, BT))
96189617
return false;
96199618

96209619
// If -flax-vector-conversions=all is specified, the types are

clang/test/Sema/riscv-rvv-lax-vector-conversions.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +f -target-feature +d -target-feature +zve64d -mvscale-min=8 -mvscale-max=8 -flax-vector-conversions=integer -ffreestanding -fsyntax-only -verify=lax-vector-integer %s
33
// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +f -target-feature +d -target-feature +zve64d -mvscale-min=8 -mvscale-max=8 -flax-vector-conversions=all -ffreestanding -fsyntax-only -verify=lax-vector-all %s
44

5-
// lax-vector-all-no-diagnostics
6-
75
// REQUIRES: riscv-registered-target
86

97
#define RVV_FIXED_ATTR __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen)))
@@ -20,6 +18,8 @@ typedef __rvv_uint64m1_t vuint64m1_t;
2018
typedef __rvv_float32m1_t vfloat32m1_t;
2119
typedef __rvv_float64m1_t vfloat64m1_t;
2220

21+
typedef __rvv_int64m2_t vint64m2_t;
22+
2323
typedef vfloat32m1_t rvv_fixed_float32m1_t RVV_FIXED_ATTR;
2424
typedef vint32m1_t rvv_fixed_int32m1_t RVV_FIXED_ATTR;
2525
typedef float gnu_fixed_float32m1_t GNU_FIXED_ATTR;
@@ -76,3 +76,17 @@ void gnu_allowed_with_all_lax_conversions() {
7676
// lax-vector-none-error@-1 {{assigning to 'vfloat64m1_t' (aka '__rvv_float64m1_t') from incompatible type}}
7777
// lax-vector-integer-error@-2 {{assigning to 'vfloat64m1_t' (aka '__rvv_float64m1_t') from incompatible type}}
7878
}
79+
80+
void not_allowed() {
81+
rvv_fixed_int32m1_t fi32m1;
82+
vint64m2_t si64m2;
83+
84+
fi32m1 = si64m2;
85+
// lax-vector-none-error@-1 {{assigning to 'rvv_fixed_int32m1_t' (vector of 16 'int' values) from incompatible type}}
86+
// lax-vector-integer-error@-2 {{assigning to 'rvv_fixed_int32m1_t' (vector of 16 'int' values) from incompatible type}}
87+
// lax-vector-all-error@-3 {{assigning to 'rvv_fixed_int32m1_t' (vector of 16 'int' values) from incompatible type}}
88+
si64m2 = fi32m1;
89+
// lax-vector-none-error@-1 {{assigning to 'vint64m2_t' (aka '__rvv_int64m2_t') from incompatible type}}
90+
// lax-vector-integer-error@-2 {{assigning to 'vint64m2_t' (aka '__rvv_int64m2_t') from incompatible type}}
91+
// lax-vector-all-error@-3 {{assigning to 'vint64m2_t' (aka '__rvv_int64m2_t') from incompatible type}}
92+
}

0 commit comments

Comments
 (0)