[llvm-branch-commits] [clang] 2c3f5d7 - [clang][AArch64][SVE] Add unary +/- operators for SVE types

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 15 00:32:29 PDT 2022


Author: David Truby
Date: 2022-08-15T09:30:54+02:00
New Revision: 2c3f5d71e3118d67ccd0c988bcc1f9bc0710574c

URL: https://github.com/llvm/llvm-project/commit/2c3f5d71e3118d67ccd0c988bcc1f9bc0710574c
DIFF: https://github.com/llvm/llvm-project/commit/2c3f5d71e3118d67ccd0c988bcc1f9bc0710574c.diff

LOG: [clang][AArch64][SVE] Add unary +/- operators for SVE types

This patch enables the unary promotion and negation operators on
SVE types.

Differential Revision: https://reviews.llvm.org/D130984

(cherry picked from commit 286d59ef6f7118c8a0600f3d281593700528a5d3)

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp
    clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
    clang/test/Sema/sizeless-1.c
    clang/test/SemaCXX/sizeless-1.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0f79978b0911c..0e24237faae5b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15603,6 +15603,8 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
               resultType->castAs<VectorType>()->getVectorKind() !=
               VectorType::AltiVecBool))
       break;
+    else if (resultType->isVLSTBuiltinType()) // SVE vectors allow + and -
+      break;
     else if (getLangOpts().CPlusPlus && // C++ [expr.unary.op]p6
              Opc == UO_Plus &&
              resultType->isPointerType())

diff  --git a/clang/test/CodeGen/aarch64-sve-vector-arith-ops.c b/clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
index c57c476032025..d7c79d7a44220 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
@@ -1650,3 +1650,143 @@ svuint32_t rem_scalar_u32(svuint32_t a, uint32_t b) {
 svuint64_t rem_scalar_u64(svuint64_t a, uint64_t b) {
   return a % b;
 }
+
+// UNARY PROMOTION
+
+// CHECK-LABEL: @prom_i8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 16 x i8> [[A:%.*]]
+//
+svint8_t prom_i8(svint8_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_i16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 8 x i16> [[A:%.*]]
+//
+svint16_t prom_i16(svint16_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_i32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 4 x i32> [[A:%.*]]
+//
+svint32_t prom_i32(svint32_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_i64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 2 x i64> [[A:%.*]]
+//
+svint64_t prom_i64(svint64_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 16 x i8> [[A:%.*]]
+//
+svuint8_t prom_u8(svuint8_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 8 x i16> [[A:%.*]]
+//
+svuint16_t prom_u16(svuint16_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 4 x i32> [[A:%.*]]
+//
+svuint32_t prom_u32(svuint32_t a) {
+  return +a;
+}
+
+// CHECK-LABEL: @prom_u64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret <vscale x 2 x i64> [[A:%.*]]
+//
+svuint64_t prom_u64(svuint64_t a) {
+  return +a;
+}
+
+// UNARY NEGATION
+
+// CHECK-LABEL: @neg_i8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 16 x i8> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 16 x i8> [[SUB]]
+//
+svint8_t neg_i8(svint8_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_i16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 8 x i16> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 8 x i16> [[SUB]]
+//
+svint16_t neg_i16(svint16_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_i32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 4 x i32> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 4 x i32> [[SUB]]
+//
+svint32_t neg_i32(svint32_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_i64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 2 x i64> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 2 x i64> [[SUB]]
+//
+svint64_t neg_i64(svint64_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 16 x i8> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 16 x i8> [[SUB]]
+//
+svuint8_t neg_u8(svuint8_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 8 x i16> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 8 x i16> [[SUB]]
+//
+svuint16_t neg_u16(svuint16_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 4 x i32> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 4 x i32> [[SUB]]
+//
+svuint32_t neg_u32(svuint32_t a) {
+  return -a;
+}
+
+// CHECK-LABEL: @neg_u64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[SUB:%.*]] = sub <vscale x 2 x i64> zeroinitializer, [[A:%.*]]
+// CHECK-NEXT:    ret <vscale x 2 x i64> [[SUB]]
+//
+svuint64_t neg_u64(svuint64_t a) {
+  return -a;
+}

diff  --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c
index 5e7e3be772e8c..64af214d206b9 100644
--- a/clang/test/Sema/sizeless-1.c
+++ b/clang/test/Sema/sizeless-1.c
@@ -187,10 +187,8 @@ void func(int sel) {
   global_int8_ptr -= 1;              // expected-error {{arithmetic on a pointer to sizeless type}}
   global_int8_ptr - global_int8_ptr; // expected-error {{arithmetic on a pointer to sizeless type}}
 
-  +init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
   ++init_int8;      // expected-error {{cannot increment value of type 'svint8_t'}}
   init_int8++;      // expected-error {{cannot increment value of type 'svint8_t'}}
-  -init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
   --init_int8;      // expected-error {{cannot decrement value of type 'svint8_t'}}
   init_int8--;      // expected-error {{cannot decrement value of type 'svint8_t'}}
   !init_int8;       // expected-error {{invalid argument type 'svint8_t'}}

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp b/clang/test/SemaCXX/sizeless-1.cpp
index 80e74db49c0f4..6c8c873f494f7 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -199,10 +199,8 @@ void func(int sel) {
   global_int8_ptr -= 1;              // expected-error {{arithmetic on a pointer to sizeless type}}
   global_int8_ptr - global_int8_ptr; // expected-error {{arithmetic on a pointer to sizeless type}}
 
-  +init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
   ++init_int8;      // expected-error {{cannot increment value of type 'svint8_t'}}
   init_int8++;      // expected-error {{cannot increment value of type 'svint8_t'}}
-  -init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
   --init_int8;      // expected-error {{cannot decrement value of type 'svint8_t'}}
   init_int8--;      // expected-error {{cannot decrement value of type 'svint8_t'}}
   !init_int8;       // expected-error {{invalid argument type 'svint8_t'}}


        


More information about the llvm-branch-commits mailing list