Skip to content

Commit 679c971

Browse files
authored
[clang][bytecode] Fix vector shifts on big-endian systems (#109800)
For shifts, the LHS and RHS element types might be different. The variable naming here could probably use some love now, but I'm trying to fix this as fast as possible. See the discussion in #108949
1 parent d4a38c8 commit 679c971

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,9 +1282,8 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
12821282
? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
12831283
: E->getOpcode();
12841284

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

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

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

13441343
for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
1345-
if (!getElem(LHSOffset, I))
1344+
if (!getElem(LHSOffset, ElemT, I))
13461345
return false;
1347-
if (!getElem(RHSOffset, I))
1346+
if (!getElem(RHSOffset, RHSElemT, I))
13481347
return false;
13491348
switch (Op) {
13501349
case BO_Add:
@@ -1372,11 +1371,11 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
13721371
return false;
13731372
break;
13741373
case BO_Shl:
1375-
if (!this->emitShl(OpT, ElemT, E))
1374+
if (!this->emitShl(OpT, RHSElemT, E))
13761375
return false;
13771376
break;
13781377
case BO_Shr:
1379-
if (!this->emitShr(OpT, ElemT, E))
1378+
if (!this->emitShr(OpT, RHSElemT, E))
13801379
return false;
13811380
break;
13821381
case BO_EQ:

0 commit comments

Comments
 (0)