Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang][AArch64][SVE] Allow write to SVE vector elements using the subscript operator #91965

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4180,7 +4180,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,

// If the base is a vector type, then we are forming a vector element lvalue
// with this subscript.
if (E->getBase()->getType()->isVectorType() &&
if (E->getBase()->getType()->isSubscriptableVectorType() &&
!isa<ExtVectorElementExpr>(E->getBase())) {
// Emit the vector as an lvalue to get its address.
LValue LHS = EmitLValue(E->getBase());
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5185,7 +5185,7 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
}

// Perform default conversions.
if (!LHSExp->getType()->getAs<VectorType>()) {
if (!LHSExp->getType()->isSubscriptableVectorType()) {
ExprResult Result = DefaultFunctionArrayLvalueConversion(LHSExp);
if (Result.isInvalid())
return ExprError();
Expand Down
22 changes: 22 additions & 0 deletions clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,25 @@ float subscript_float32(svfloat32_t a, size_t b) {
double subscript_float64(svfloat64_t a, size_t b) {
return a[b];
}

// CHECK-LABEL: @subscript_write_float32(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[VECINS:%.*]] = insertelement <vscale x 4 x float> [[A:%.*]], float 1.000000e+00, i64 [[B:%.*]]
// CHECK-NEXT: ret <vscale x 4 x float> [[VECINS]]
//
svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
a[b] = 1.0f;
momchil-velikov marked this conversation as resolved.
Show resolved Hide resolved
return a;
}

// CHECK-LABEL: @subscript_read_write_float32(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <vscale x 4 x float> [[A:%.*]], i64 [[B:%.*]]
// CHECK-NEXT: [[ADD:%.*]] = fadd float [[VECEXT]], 1.000000e+00
// CHECK-NEXT: [[VECINS:%.*]] = insertelement <vscale x 4 x float> [[A]], float [[ADD]], i64 [[B]]
// CHECK-NEXT: ret <vscale x 4 x float> [[VECINS]]
//
svfloat32_t subscript_read_write_float32(svfloat32_t a, size_t b) {
a[b] += 1.0f;
return a;
}
Loading