Skip to content

Commit dd0d956

Browse files
authored
[clang][bytecode] Support vector-to-vector bitcasts (#118230)
1 parent d9d656e commit dd0d956

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
448448

449449
QualType SubExprTy = SubExpr->getType();
450450
std::optional<PrimType> FromT = classify(SubExprTy);
451-
// Casts from integer to vectors in C.
452-
if (FromT && CE->getType()->isVectorType())
451+
// Casts from integer/vector to vector.
452+
if (CE->getType()->isVectorType())
453453
return this->emitBuiltinBitCast(CE);
454454

455455
std::optional<PrimType> ToT = classify(CE->getType());
@@ -6502,7 +6502,7 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
65026502
// we later assume it to be one (i.e. a PT_Ptr). However,
65036503
// we call this function for other utility methods where
65046504
// a bitcast might be useful, so convert it to a PT_Ptr in that case.
6505-
if (SubExpr->isGLValue()) {
6505+
if (SubExpr->isGLValue() || FromType->isVectorType()) {
65066506
if (!this->visit(SubExpr))
65076507
return false;
65086508
} else if (std::optional<PrimType> FromT = classify(SubExpr)) {

clang/test/AST/ByteCode/altivec.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -target-feature +vsx -fsyntax-only -verify=expected,both %s
2+
// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both %s
3+
// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,both %s
4+
// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both %s
5+
6+
// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -target-feature +vsx -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s
7+
// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s
8+
// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s
9+
// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -target-feature -vsx -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s
10+
11+
// both-no-diagnostics.
12+
13+
/// From test/Parser/altivec.c
14+
vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
15+
vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
16+
vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
17+
vector int v4 = (vector int)(1, 2, 3, 4);
18+
vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
19+
vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));

clang/test/AST/ByteCode/vectors.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ namespace Vector {
5555
static_assert(__builtin_vectorelements(v2) == (32 / sizeof(double)), "");
5656
}
5757

58-
/// FIXME: We need to support BitCasts between vector types.
5958
namespace {
6059
typedef float __attribute__((vector_size(16))) VI42;
61-
constexpr VI42 A2 = A; // expected-error {{must be initialized by a constant expression}}
60+
constexpr VI42 A2 = A;
6261
}
6362

6463
namespace BoolToSignedIntegralCast{

0 commit comments

Comments
 (0)