Skip to content

Commit

Permalink
[Clang][AArch64][SVE] Allow write to SVE vector elements using the su…
Browse files Browse the repository at this point in the history
…bscript 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
  • Loading branch information
momchil-velikov committed May 21, 2024
1 parent f52d29c commit b1b69ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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
10 changes: 10 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,13 @@ 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;
return a;
}

0 comments on commit b1b69ff

Please sign in to comment.