Skip to content

Commit 7fc3ff1

Browse files
[Clang][AArch64][SVE] Allow write to SVE vector elements using the subscript operator
The patch at https://reviews.llvm.org/D122732 introduced using the array subscript operator for SVE vectors, however it also causes an ICE when the subscripting expression is used as an lvalue. This patches fixes the error. Lvalue subscripting expressions are emitted as LLVM IR `insertvector`. Change-Id: I46d0333d8ed8508cd9cd23e02dd1c2d48fb74cd2
1 parent 435f310 commit 7fc3ff1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4180,7 +4180,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
41804180

41814181
// If the base is a vector type, then we are forming a vector element lvalue
41824182
// with this subscript.
4183-
if (E->getBase()->getType()->isVectorType() &&
4183+
if (E->getBase()->getType()->isSubscriptableVectorType() &&
41844184
!isa<ExtVectorElementExpr>(E->getBase())) {
41854185
// Emit the vector as an lvalue to get its address.
41864186
LValue LHS = EmitLValue(E->getBase());

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5227,7 +5227,7 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
52275227
}
52285228

52295229
// Perform default conversions.
5230-
if (!LHSExp->getType()->getAs<VectorType>()) {
5230+
if (!LHSExp->getType()->isSubscriptableVectorType()) {
52315231
ExprResult Result = DefaultFunctionArrayLvalueConversion(LHSExp);
52325232
if (Result.isInvalid())
52335233
return ExprError();

clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ float subscript_float32(svfloat32_t a, size_t b) {
8888
double subscript_float64(svfloat64_t a, size_t b) {
8989
return a[b];
9090
}
91+
92+
// CHECK-LABEL: @subscript_write_float32(
93+
// CHECK-NEXT: entry:
94+
// CHECK-NEXT: [[VECINS:%.*]] = insertelement <vscale x 4 x float> [[A:%.*]], float 1.000000e+00, i64 [[B:%.*]]
95+
// CHECK-NEXT: ret <vscale x 4 x float> [[VECINS]]
96+
//
97+
svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
98+
a[b] = 1.0f;
99+
return a;
100+
}

0 commit comments

Comments
 (0)