Skip to content

[clang][bytecode] Fix vector shifts on big-endian systems #109800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,9 +1282,8 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
: E->getOpcode();

// The LHS and RHS of a comparison operator must have the same type. So we
// just use LHS vector element type here.
PrimType ElemT = this->classifyVectorElementType(LHS->getType());
PrimType RHSElemT = this->classifyVectorElementType(RHS->getType());
PrimType ResultElemT = this->classifyVectorElementType(E->getType());

// Evaluate LHS and save value to LHSOffset.
Expand Down Expand Up @@ -1312,7 +1311,7 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
PrimType PromotT = classifyPrim(PromotTy);
PrimType OpT = NeedIntPromot ? PromotT : ElemT;

auto getElem = [=](unsigned Offset, unsigned Index) {
auto getElem = [=](unsigned Offset, PrimType ElemT, unsigned Index) {
if (!this->emitGetLocal(PT_Ptr, Offset, E))
return false;
if (!this->emitArrayElemPop(ElemT, Index, E))
Expand Down Expand Up @@ -1342,9 +1341,9 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
}

for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
if (!getElem(LHSOffset, I))
if (!getElem(LHSOffset, ElemT, I))
return false;
if (!getElem(RHSOffset, I))
if (!getElem(RHSOffset, RHSElemT, I))
return false;
switch (Op) {
case BO_Add:
Expand Down Expand Up @@ -1372,11 +1371,11 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
return false;
break;
case BO_Shl:
if (!this->emitShl(OpT, ElemT, E))
if (!this->emitShl(OpT, RHSElemT, E))
return false;
break;
case BO_Shr:
if (!this->emitShr(OpT, ElemT, E))
if (!this->emitShr(OpT, RHSElemT, E))
return false;
break;
case BO_EQ:
Expand Down
Loading