[clang] [ARM] Change NEON poly type to be unsigned (#56781) (PR #80691)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 07:07:28 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Alfie Richards (AlfieRichardsArm)

<details>
<summary>Changes</summary>

This is to be inline with the Arm C Language Specification. (https://github.com/ARM-software/acle/releases/download/r2022Q2/acle-2022Q2.pdf) and with GCC.

This fixes https://github.com/llvm/llvm-project/issues/56781

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


6 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+4-8) 
- (modified) clang/lib/Sema/SemaType.cpp (+4-17) 
- (modified) clang/test/CodeGenCXX/mangle-neon-vectors.cpp (-5) 
- (modified) clang/test/CodeGenCXX/poly-unsigned.cpp (+5-8) 
- (modified) clang/test/Sema/neon-vector-types.c (+2-2) 
- (modified) clang/utils/TableGen/NeonEmitter.cpp (+2-7) 


``````````diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b071a02ca3713..17fdfb4d448c6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3017,7 +3017,7 @@ static unsigned RFT(unsigned t, bool shift = false, bool ForceQuad = false) {
 /// the vector type specified by the NeonTypeFlags.  This is used to check
 /// the pointer arguments for Neon load/store intrinsics.
 static QualType getNeonEltType(NeonTypeFlags Flags, ASTContext &Context,
-                               bool IsPolyUnsigned, bool IsInt64Long) {
+                               bool IsInt64Long) {
   switch (Flags.getEltType()) {
   case NeonTypeFlags::Int8:
     return Flags.isUnsigned() ? Context.UnsignedCharTy : Context.SignedCharTy;
@@ -3032,9 +3032,9 @@ static QualType getNeonEltType(NeonTypeFlags Flags, ASTContext &Context,
       return Flags.isUnsigned() ? Context.UnsignedLongLongTy
                                 : Context.LongLongTy;
   case NeonTypeFlags::Poly8:
-    return IsPolyUnsigned ? Context.UnsignedCharTy : Context.SignedCharTy;
+    return Context.UnsignedCharTy;
   case NeonTypeFlags::Poly16:
-    return IsPolyUnsigned ? Context.UnsignedShortTy : Context.ShortTy;
+    return Context.UnsignedShortTy;
   case NeonTypeFlags::Poly64:
     if (IsInt64Long)
       return Context.UnsignedLongTy;
@@ -3399,13 +3399,9 @@ bool Sema::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
     ExprResult RHS = DefaultFunctionArrayLvalueConversion(Arg);
     QualType RHSTy = RHS.get()->getType();
 
-    llvm::Triple::ArchType Arch = TI.getTriple().getArch();
-    bool IsPolyUnsigned = Arch == llvm::Triple::aarch64 ||
-                          Arch == llvm::Triple::aarch64_32 ||
-                          Arch == llvm::Triple::aarch64_be;
     bool IsInt64Long = TI.getInt64Type() == TargetInfo::SignedLong;
     QualType EltTy =
-        getNeonEltType(NeonTypeFlags(TV), Context, IsPolyUnsigned, IsInt64Long);
+        getNeonEltType(NeonTypeFlags(TV), Context, IsInt64Long);
     if (HasConstPtr)
       EltTy = EltTy.withConst();
     QualType LHSTy = Context.getPointerType(EltTy);
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index aee2c9c4a7ded..1531a764de626 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8413,24 +8413,11 @@ static bool isPermittedNeonBaseType(QualType &Ty, VectorKind VecKind, Sema &S) {
 
   llvm::Triple Triple = S.Context.getTargetInfo().getTriple();
 
-  // Signed poly is mathematically wrong, but has been baked into some ABIs by
-  // now.
-  bool IsPolyUnsigned = Triple.getArch() == llvm::Triple::aarch64 ||
-                        Triple.getArch() == llvm::Triple::aarch64_32 ||
-                        Triple.getArch() == llvm::Triple::aarch64_be;
   if (VecKind == VectorKind::NeonPoly) {
-    if (IsPolyUnsigned) {
-      // AArch64 polynomial vectors are unsigned.
-      return BTy->getKind() == BuiltinType::UChar ||
-             BTy->getKind() == BuiltinType::UShort ||
-             BTy->getKind() == BuiltinType::ULong ||
-             BTy->getKind() == BuiltinType::ULongLong;
-    } else {
-      // AArch32 polynomial vectors are signed.
-      return BTy->getKind() == BuiltinType::SChar ||
-             BTy->getKind() == BuiltinType::Short ||
-             BTy->getKind() == BuiltinType::LongLong;
-    }
+    return BTy->getKind() == BuiltinType::UChar ||
+           BTy->getKind() == BuiltinType::UShort ||
+           BTy->getKind() == BuiltinType::ULong ||
+           BTy->getKind() == BuiltinType::ULongLong;
   }
 
   // Non-polynomial vector types: the usual suspects are allowed, as well as
diff --git a/clang/test/CodeGenCXX/mangle-neon-vectors.cpp b/clang/test/CodeGenCXX/mangle-neon-vectors.cpp
index cb5e40be6a6df..e75273b373a61 100644
--- a/clang/test/CodeGenCXX/mangle-neon-vectors.cpp
+++ b/clang/test/CodeGenCXX/mangle-neon-vectors.cpp
@@ -6,13 +6,8 @@
 typedef float float32_t;
 typedef double float64_t;
 typedef __fp16 float16_t;
-#if defined(__aarch64__)
 typedef unsigned char poly8_t;
 typedef unsigned short poly16_t;
-#else
-typedef signed char poly8_t;
-typedef short poly16_t;
-#endif
 typedef unsigned __INT64_TYPE__ uint64_t;
 
 #if defined(__ARM_FEATURE_BF16)
diff --git a/clang/test/CodeGenCXX/poly-unsigned.cpp b/clang/test/CodeGenCXX/poly-unsigned.cpp
index 31970e495777d..1b27825b4617b 100644
--- a/clang/test/CodeGenCXX/poly-unsigned.cpp
+++ b/clang/test/CodeGenCXX/poly-unsigned.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -triple arm64-apple-ios -target-feature +neon -ffreestanding -S -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-UNSIGNED-POLY %s
-// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -ffreestanding -S -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-UNSIGNED-POLY %s
-// RUN: %clang_cc1 -triple armv7-apple-ios -ffreestanding -target-cpu cortex-a8 -S -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-SIGNED-POLY %s
+// RUN: %clang_cc1 -triple arm64-apple-ios -target-feature +neon -ffreestanding -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -ffreestanding -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-ios -ffreestanding -target-cpu cortex-a8 -S -emit-llvm -o - %s | FileCheck %s
 
 // REQUIRES: aarch64-registered-target || arm-registered-target
 
@@ -12,11 +12,8 @@
 // so for now it got that wrong.
 
 poly16_t test_poly8(poly8_t pIn) {
-// CHECK-UNSIGNED-POLY: @_Z10test_poly8h
-// CHECK-UNSIGNED-POLY: zext i8 {{.*}} to i16
-
-// CHECK-SIGNED-POLY: @_Z10test_poly8a
-// CHECK-SIGNED-POLY: sext i8 {{.*}} to i16
+// CHECK: @_Z10test_poly8h
+// CHECK: zext i8 {{.*}} to i16
 
   return pIn;
 }
diff --git a/clang/test/Sema/neon-vector-types.c b/clang/test/Sema/neon-vector-types.c
index fbe7d854dfd7d..3dfbe5e002ef2 100644
--- a/clang/test/Sema/neon-vector-types.c
+++ b/clang/test/Sema/neon-vector-types.c
@@ -2,8 +2,8 @@
 // RUN: %clang_cc1 %s -triple armv8 -target-feature +neon -fsyntax-only -verify
 
 typedef float float32_t;
-typedef signed char poly8_t;
-typedef short poly16_t;
+typedef unsigned char poly8_t;
+typedef unsigned short poly16_t;
 typedef unsigned __INT64_TYPE__ uint64_t;
 
 // Define some valid Neon types.
diff --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp
index 04e1acc270500..e5135c2274e6c 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -1339,7 +1339,7 @@ void Intrinsic::emitBodyAsBuiltinCall() {
       CastToType.makeInteger(8, true);
       Arg = "(" + CastToType.str() + ")" + Arg;
     } else if (CastToType.isVector() && LocalCK == ClassI) {
-      if (CastToType.isInteger())
+      if (CastToType.isInteger() || CastToType.isPoly())
         CastToType.makeSigned();
       Arg = "(" + CastToType.str() + ")" + Arg;
     }
@@ -2380,16 +2380,11 @@ void NeonEmitter::run(raw_ostream &OS) {
 
   OS << "#include <arm_vector_types.h>\n";
 
-  // For now, signedness of polynomial types depends on target
-  OS << "#ifdef __aarch64__\n";
   OS << "typedef uint8_t poly8_t;\n";
   OS << "typedef uint16_t poly16_t;\n";
   OS << "typedef uint64_t poly64_t;\n";
+  OS << "#ifdef __aarch64__\n";
   OS << "typedef __uint128_t poly128_t;\n";
-  OS << "#else\n";
-  OS << "typedef int8_t poly8_t;\n";
-  OS << "typedef int16_t poly16_t;\n";
-  OS << "typedef int64_t poly64_t;\n";
   OS << "#endif\n";
   emitNeonTypeDefs("PcQPcPsQPsPlQPl", OS);
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/80691


More information about the cfe-commits mailing list