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

2024-05-22 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov closed 
https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-21 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-21 Thread Momchil Velikov via cfe-commits

momchil-velikov wrote:

Rebased.

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-21 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/91965

>From b1b69ffcaf4525a66dde1ae7f1a022c85204a579 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 20 May 2024 16:25:43 +0100
Subject: [PATCH 1/2] [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
---
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/Sema/SemaExpr.cpp   |  2 +-
 clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c | 10 ++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index cd1c48b420382..6f9237e2067f5 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -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(E->getBase())) {
 // Emit the vector as an lvalue to get its address.
 LValue LHS = EmitLValue(E->getBase());
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 326879b0883fa..49541edf106e1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5185,7 +5185,7 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
   }
 
   // Perform default conversions.
-  if (!LHSExp->getType()->getAs()) {
+  if (!LHSExp->getType()->isSubscriptableVectorType()) {
 ExprResult Result = DefaultFunctionArrayLvalueConversion(LHSExp);
 if (Result.isInvalid())
   return ExprError();
diff --git a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c 
b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
index fb60c6d100ce6..634423765c4c3 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -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  
[[A:%.*]], float 1.00e+00, i64 [[B:%.*]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
+  a[b] = 1.0f;
+  return a;
+}

>From 08a155b49a6b9c859ba8569170e0f71e63b76735 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 20 May 2024 16:26:06 +0100
Subject: [PATCH 2/2] [fixiup] Add a test using compound assignment operator

Change-Id: I81e1fd4f23eb65a96e71015de7a4562fcbc53c0f
---
 .../test/CodeGen/aarch64-sve-vector-subscript-ops.c  | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c 
b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
index 634423765c4c3..52a05d010de9b 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -98,3 +98,15 @@ svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) 
{
   a[b] = 1.0f;
   return a;
 }
+
+// CHECK-LABEL: @subscript_read_write_float32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECEXT:%.*]] = extractelement  
[[A:%.*]], i64 [[B:%.*]]
+// CHECK-NEXT:[[ADD:%.*]] = fadd float [[VECEXT]], 1.00e+00
+// CHECK-NEXT:[[VECINS:%.*]] = insertelement  [[A]], 
float [[ADD]], i64 [[B]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_read_write_float32(svfloat32_t a, size_t b) {
+  a[b] += 1.0f;
+  return a;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-20 Thread Momchil Velikov via cfe-commits


@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {

momchil-velikov wrote:

Split out to https://github.com/llvm/llvm-project/pull/92778

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-20 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/91965

>From 435f3104e68ef278196417c293093131258c549d Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 20 May 2024 15:43:31 +0100
Subject: [PATCH 1/3] [Clang][Sema] Refactor handling of vector subscript
 expressions (NFC)

Change-Id: I514431a482ffa0a2d906c019b6e374bf4607571e
---
 clang/include/clang/AST/Type.h |  5 
 clang/lib/Sema/SemaExpr.cpp| 44 +++---
 2 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index da3834f19ca04..9a5c6e8d562c3 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2523,6 +2523,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isVectorType() const;// GCC vector type.
   bool isExtVectorType() const; // Extended vector type.
   bool isExtVectorBoolType() const; // Extended vector type with 
bool element.
+  bool isSubscriptableVectorType() const;
   bool isMatrixType() const;// Matrix type.
   bool isConstantMatrixType() const;// Constant matrix type.
   bool isDependentAddressSpaceType() const; // value-dependent address 
space qualifier
@@ -7729,6 +7730,10 @@ inline bool Type::isExtVectorBoolType() const {
   return cast(CanonicalType)->getElementType()->isBooleanType();
 }
 
+inline bool Type::isSubscriptableVectorType() const {
+  return isVectorType() || isSveVLSBuiltinType();
+}
+
 inline bool Type::isMatrixType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5ecfdee21f09d..c86f1d9c8076e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5283,36 +5283,22 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
 << ResultType << BaseExpr->getSourceRange();
   return ExprError();
 }
-  } else if (const VectorType *VTy = LHSTy->getAs()) {
-BaseExpr = LHSExp;// vectors: V[123]
-IndexExpr = RHSExp;
-// We apply C++ DR1213 to vector subscripting too.
-if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) {
-  ExprResult Materialized = TemporaryMaterializationConversion(LHSExp);
-  if (Materialized.isInvalid())
-return ExprError();
-  LHSExp = Materialized.get();
+  } else if (LHSTy->isSubscriptableVectorType()) {
+if (LHSTy->isBuiltinType() &&
+LHSTy->getAs()->isSveVLSBuiltinType()) {
+  const BuiltinType *BTy = LHSTy->getAs();
+  if (BTy->isSVEBool())
+return ExprError(Diag(LLoc, diag::err_subscript_svbool_t)
+ << LHSExp->getSourceRange()
+ << RHSExp->getSourceRange());
+  ResultType = BTy->getSveEltType(Context);
+} else {
+  const VectorType *VTy = LHSTy->getAs();
+  ResultType = VTy->getElementType();
 }
-VK = LHSExp->getValueKind();
-if (VK != VK_PRValue)
-  OK = OK_VectorComponent;
-
-ResultType = VTy->getElementType();
-QualType BaseType = BaseExpr->getType();
-Qualifiers BaseQuals = BaseType.getQualifiers();
-Qualifiers MemberQuals = ResultType.getQualifiers();
-Qualifiers Combined = BaseQuals + MemberQuals;
-if (Combined != MemberQuals)
-  ResultType = Context.getQualifiedType(ResultType, Combined);
-  } else if (LHSTy->isBuiltinType() &&
- LHSTy->getAs()->isSveVLSBuiltinType()) {
-const BuiltinType *BTy = LHSTy->getAs();
-if (BTy->isSVEBool())
-  return ExprError(Diag(LLoc, diag::err_subscript_svbool_t)
-   << LHSExp->getSourceRange() << 
RHSExp->getSourceRange());
-
-BaseExpr = LHSExp;
+BaseExpr = LHSExp; // vectors: V[123]
 IndexExpr = RHSExp;
+// We apply C++ DR1213 to vector subscripting too.
 if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) {
   ExprResult Materialized = TemporaryMaterializationConversion(LHSExp);
   if (Materialized.isInvalid())
@@ -5323,8 +5309,6 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
 if (VK != VK_PRValue)
   OK = OK_VectorComponent;
 
-ResultType = BTy->getSveEltType(Context);
-
 QualType BaseType = BaseExpr->getType();
 Qualifiers BaseQuals = BaseType.getQualifiers();
 Qualifiers MemberQuals = ResultType.getQualifiers();

>From 7fc3ff1758fa424bdbea3c847aede260f7598814 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 20 May 2024 16:25:43 +0100
Subject: [PATCH 2/3] [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`.

Ch

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

2024-05-17 Thread Eli Friedman via cfe-commits


@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {

efriedma-quic wrote:

In that case, it might make sense to introduce a helper 
Type::isSubscriptableVectorType() helper to types, so we can easily find all 
the places that care about this.

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-17 Thread Momchil Velikov via cfe-commits


@@ -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  
[[A:%.*]], float 1.00e+00, i64 [[B:%.*]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
+  a[b] = 1.0f;

momchil-velikov wrote:

Done.

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-17 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/91965

>From fd4a31c1eb48db410f5445f45243dfbc1d9d22ab Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 13 May 2024 14:27:51 +0100
Subject: [PATCH 1/2] [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`.
---
 clang/lib/CodeGen/CGExpr.cpp  |  6 --
 clang/lib/Sema/SemaExpr.cpp   |  4 +++-
 clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c | 10 ++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index d96c7bb1e5682..37b8b723937b7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {
 // Emit the vector as an lvalue to get its address.
 LValue LHS = EmitLValue(E->getBase());
 auto *Idx = EmitIdxAfterBase(/*Promote*/false);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e0aae6333e1a1..f3983a3cbefb1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5227,7 +5227,9 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
   }
 
   // Perform default conversions.
-  if (!LHSExp->getType()->getAs()) {
+  if (!LHSExp->getType()->getAs() &&
+  !(LHSExp->getType()->isBuiltinType() &&
+LHSExp->getType()->getAs()->isSveVLSBuiltinType())) {
 ExprResult Result = DefaultFunctionArrayLvalueConversion(LHSExp);
 if (Result.isInvalid())
   return ExprError();
diff --git a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c 
b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
index fb60c6d100ce6..634423765c4c3 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -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  
[[A:%.*]], float 1.00e+00, i64 [[B:%.*]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
+  a[b] = 1.0f;
+  return a;
+}

>From fec051ff91df9cc8fca4d0571fe77a18cfb58072 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Fri, 17 May 2024 13:20:18 +0100
Subject: [PATCH 2/2] [fixiup] Add a test using compound assignment operator

Change-Id: I81e1fd4f23eb65a96e71015de7a4562fcbc53c0f
---
 .../test/CodeGen/aarch64-sve-vector-subscript-ops.c  | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c 
b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
index 634423765c4c3..52a05d010de9b 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -98,3 +98,15 @@ svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) 
{
   a[b] = 1.0f;
   return a;
 }
+
+// CHECK-LABEL: @subscript_read_write_float32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECEXT:%.*]] = extractelement  
[[A:%.*]], i64 [[B:%.*]]
+// CHECK-NEXT:[[ADD:%.*]] = fadd float [[VECEXT]], 1.00e+00
+// CHECK-NEXT:[[VECINS:%.*]] = insertelement  [[A]], 
float [[ADD]], i64 [[B]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_read_write_float32(svfloat32_t a, size_t b) {
+  a[b] += 1.0f;
+  return a;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-17 Thread Momchil Velikov via cfe-commits


@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {

momchil-velikov wrote:

AFAICT here 
https://github.com/llvm/llvm-project/blob/371eccd5dfed88c8e76449233d8388c12be3464b/clang/lib/Sema/SemaExpr.cpp#L5307
 we are enabling array subscripts for SVE only. 

Perhaps we can be generalised to any size-less vector type, in a followup 
patch, @jacquesguan , what do you think?


https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-17 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/91965

>From 2e081d74e87ad14fdf6d950d3e3da6bed07ee723 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 13 May 2024 14:27:51 +0100
Subject: [PATCH] [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`.
---
 clang/lib/CodeGen/CGExpr.cpp  |  6 --
 clang/lib/Sema/SemaExpr.cpp   |  4 +++-
 clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c | 10 ++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index d96c7bb1e5682..37b8b723937b7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {
 // Emit the vector as an lvalue to get its address.
 LValue LHS = EmitLValue(E->getBase());
 auto *Idx = EmitIdxAfterBase(/*Promote*/false);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bb4b116fd73ca..fd16be30bd848 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5383,7 +5383,9 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
   }
 
   // Perform default conversions.
-  if (!LHSExp->getType()->getAs()) {
+  if (!LHSExp->getType()->getAs() &&
+  !(LHSExp->getType()->isBuiltinType() &&
+LHSExp->getType()->getAs()->isSveVLSBuiltinType())) {
 ExprResult Result = DefaultFunctionArrayLvalueConversion(LHSExp);
 if (Result.isInvalid())
   return ExprError();
diff --git a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c 
b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
index fb60c6d100ce6..634423765c4c3 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -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  
[[A:%.*]], float 1.00e+00, i64 [[B:%.*]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
+  a[b] = 1.0f;
+  return a;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-16 Thread David Truby via cfe-commits

https://github.com/DavidTruby approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-13 Thread Eli Friedman via cfe-commits


@@ -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  
[[A:%.*]], float 1.00e+00, i64 [[B:%.*]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
+  a[b] = 1.0f;

efriedma-quic wrote:

Please also add a test for a compound op (`a[b]+=1.f`).

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-13 Thread Eli Friedman via cfe-commits


@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {

efriedma-quic wrote:

isSizelessVectorType()?

https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Momchil Velikov (momchil-velikov)


Changes

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 `insertelement`.


---
Full diff: https://github.com/llvm/llvm-project/pull/91965.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+4-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3-1) 
- (modified) clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c (+10) 


``diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index d96c7bb1e5682..37b8b723937b7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {
 // Emit the vector as an lvalue to get its address.
 LValue LHS = EmitLValue(E->getBase());
 auto *Idx = EmitIdxAfterBase(/*Promote*/false);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bb4b116fd73ca..fd16be30bd848 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5383,7 +5383,9 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
   }
 
   // Perform default conversions.
-  if (!LHSExp->getType()->getAs()) {
+  if (!LHSExp->getType()->getAs() &&
+  !(LHSExp->getType()->isBuiltinType() &&
+LHSExp->getType()->getAs()->isSveVLSBuiltinType())) {
 ExprResult Result = DefaultFunctionArrayLvalueConversion(LHSExp);
 if (Result.isInvalid())
   return ExprError();
diff --git a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c 
b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
index fb60c6d100ce6..634423765c4c3 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -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  
[[A:%.*]], float 1.00e+00, i64 [[B:%.*]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
+  a[b] = 1.0f;
+  return a;
+}

``




https://github.com/llvm/llvm-project/pull/91965
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-13 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov created 
https://github.com/llvm/llvm-project/pull/91965

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 `insertelement`.


>From 2e081d74e87ad14fdf6d950d3e3da6bed07ee723 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 13 May 2024 14:27:51 +0100
Subject: [PATCH] [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`.
---
 clang/lib/CodeGen/CGExpr.cpp  |  6 --
 clang/lib/Sema/SemaExpr.cpp   |  4 +++-
 clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c | 10 ++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index d96c7bb1e5682..37b8b723937b7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4180,8 +4180,10 @@ 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() &&
-  !isa(E->getBase())) {
+  if (QualType BaseTy = E->getBase()->getType();
+  (BaseTy->isVectorType() && !isa(E->getBase())) ||
+  (BaseTy->isBuiltinType() &&
+   BaseTy->getAs()->isSveVLSBuiltinType())) {
 // Emit the vector as an lvalue to get its address.
 LValue LHS = EmitLValue(E->getBase());
 auto *Idx = EmitIdxAfterBase(/*Promote*/false);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bb4b116fd73ca..fd16be30bd848 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5383,7 +5383,9 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
   }
 
   // Perform default conversions.
-  if (!LHSExp->getType()->getAs()) {
+  if (!LHSExp->getType()->getAs() &&
+  !(LHSExp->getType()->isBuiltinType() &&
+LHSExp->getType()->getAs()->isSveVLSBuiltinType())) {
 ExprResult Result = DefaultFunctionArrayLvalueConversion(LHSExp);
 if (Result.isInvalid())
   return ExprError();
diff --git a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c 
b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
index fb60c6d100ce6..634423765c4c3 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -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  
[[A:%.*]], float 1.00e+00, i64 [[B:%.*]]
+// CHECK-NEXT:ret  [[VECINS]]
+//
+svfloat32_t subscript_write_float32(svfloat32_t a, size_t b) {
+  a[b] = 1.0f;
+  return a;
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits