https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/118230
None >From 3bdcf86f356fb6579bebf35ed636b0eae9bf24fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sun, 1 Dec 2024 20:24:05 +0100 Subject: [PATCH] [clang][bytecode] Support vector-to-vector bitcasts --- clang/lib/AST/ByteCode/Compiler.cpp | 6 +++--- clang/test/AST/ByteCode/altivec.c | 19 +++++++++++++++++++ clang/test/AST/ByteCode/vectors.cpp | 3 +-- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 clang/test/AST/ByteCode/altivec.c diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index f4cc284dfb6abf..754affffb8f04a 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -448,8 +448,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { QualType SubExprTy = SubExpr->getType(); std::optional<PrimType> FromT = classify(SubExprTy); - // Casts from integer to vectors in C. - if (FromT && CE->getType()->isVectorType()) + // Casts from integer/vector to vector. + if (CE->getType()->isVectorType()) return this->emitBuiltinBitCast(CE); std::optional<PrimType> ToT = classify(CE->getType()); @@ -6502,7 +6502,7 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) { // we later assume it to be one (i.e. a PT_Ptr). However, // we call this function for other utility methods where // a bitcast might be useful, so convert it to a PT_Ptr in that case. - if (SubExpr->isGLValue()) { + if (SubExpr->isGLValue() || FromType->isVectorType()) { if (!this->visit(SubExpr)) return false; } else if (std::optional<PrimType> FromT = classify(SubExpr)) { diff --git a/clang/test/AST/ByteCode/altivec.c b/clang/test/AST/ByteCode/altivec.c new file mode 100644 index 00000000000000..39caedc9949d20 --- /dev/null +++ b/clang/test/AST/ByteCode/altivec.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -target-feature +vsx -fsyntax-only -verify=expected,both %s +// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both %s +// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,both %s +// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both %s + +// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -target-feature +vsx -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s +// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s +// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s +// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s + +// both-no-diagnostics. + +/// From test/Parser/altivec.c +vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); +vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); +vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); +vector int v4 = (vector int)(1, 2, 3, 4); +vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); +vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); diff --git a/clang/test/AST/ByteCode/vectors.cpp b/clang/test/AST/ByteCode/vectors.cpp index a0aace44f3c981..08e2ca2adbf5cd 100644 --- a/clang/test/AST/ByteCode/vectors.cpp +++ b/clang/test/AST/ByteCode/vectors.cpp @@ -55,10 +55,9 @@ namespace Vector { static_assert(__builtin_vectorelements(v2) == (32 / sizeof(double)), ""); } -/// FIXME: We need to support BitCasts between vector types. namespace { typedef float __attribute__((vector_size(16))) VI42; - constexpr VI42 A2 = A; // expected-error {{must be initialized by a constant expression}} + constexpr VI42 A2 = A; } namespace BoolToSignedIntegralCast{ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits