[clang] [clang][bytecode] Support vector-to-vector bitcasts (PR #118230)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 1 11:26:13 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/118230.diff
3 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3-3)
- (added) clang/test/AST/ByteCode/altivec.c (+19)
- (modified) clang/test/AST/ByteCode/vectors.cpp (+1-2)
``````````diff
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{
``````````
</details>
https://github.com/llvm/llvm-project/pull/118230
More information about the cfe-commits
mailing list