Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 5b2f8df

Browse files
committed
Fix expansion of boolean simd vectors to expand lanes up to the correct lane size (2,4,8 or 16). This prevents i1xN vector constant creation from getting erroneously expanded up to a nonexisting Bool1x128 type.
1 parent f63a464 commit 5b2f8df

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

lib/Target/JSBackend/JSBackend.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,29 @@ std::string JSWriter::getAssignIfNeeded(const Value *V) {
990990
return std::string();
991991
}
992992

993+
int SIMDNumElements(VectorType *t) {
994+
assert(t->getElementType()->getPrimitiveSizeInBits() <= 128);
995+
996+
if (t->getElementType()->getPrimitiveSizeInBits() == 1) { // Bool8x16, Bool16x8, Bool32x4 or Bool64x2
997+
if (t->getNumElements() <= 2) return 2;
998+
if (t->getNumElements() <= 4) return 4;
999+
if (t->getNumElements() <= 8) return 8;
1000+
if (t->getNumElements() <= 16) return 16;
1001+
// fall-through to error
1002+
} else { // Int/Float 8x16, 16x8, 32x4 or 64x2
1003+
if (t->getElementType()->getPrimitiveSizeInBits() > 32 && t->getNumElements() <= 2) return 2;
1004+
if (t->getElementType()->getPrimitiveSizeInBits() > 16 && t->getNumElements() <= 4) return 4;
1005+
if (t->getElementType()->getPrimitiveSizeInBits() > 8 && t->getNumElements() <= 8) return 8;
1006+
if (t->getElementType()->getPrimitiveSizeInBits() <= 8 && t->getNumElements() <= 16) return 16;
1007+
// fall-through to error
1008+
}
1009+
errs() << *t << "\n";
1010+
report_fatal_error("Unsupported type!");
1011+
return 0;
1012+
}
1013+
9931014
const char *SIMDType(VectorType *t) {
994-
int primSize = t->getElementType()->getPrimitiveSizeInBits();
995-
assert(primSize <= 128);
1015+
assert(t->getElementType()->getPrimitiveSizeInBits() <= 128);
9961016

9971017
if (t->getElementType()->isIntegerTy()) {
9981018
if (t->getElementType()->getPrimitiveSizeInBits() == 1) {
@@ -1645,8 +1665,7 @@ std::string JSWriter::getConstantVector(const ConstantVectorType *C) {
16451665
}
16461666
}
16471667

1648-
int primSize = C->getType()->getElementType()->getPrimitiveSizeInBits();
1649-
const int SIMDJsRetNumElements = 128 / primSize;
1668+
const int SIMDJsRetNumElements = SIMDNumElements(C->getType());
16501669

16511670
std::string c;
16521671
if (!hasSpecialNaNs) {
@@ -1852,7 +1871,7 @@ std::string JSWriter::getSIMDCast(VectorType *fromType, VectorType *toType, cons
18521871
}
18531872

18541873
// Promote smaller than 128-bit vector types to 128-bit since smaller ones do not exist in SIMD.js. (pad with zero lanes)
1855-
int toNumElems = 128 / toPrimSize;
1874+
const int toNumElems = SIMDNumElements(toType);
18561875

18571876
bool fromIsBool = (fromInt && fromPrimSize == 1);
18581877
bool toIsBool = (toInt && toPrimSize == 1);
@@ -1899,8 +1918,8 @@ void JSWriter::generateShuffleVectorExpression(const ShuffleVectorInst *SVI, raw
18991918
int OpNumElements = op0->getNumElements();
19001919
int ResultNumElements = SVI->getType()->getNumElements();
19011920
// Promote smaller than 128-bit vector types to 128-bit since smaller ones do not exist in SIMD.js. (pad with zero lanes)
1902-
int SIMDJsRetNumElements = 128 / cast<VectorType>(SVI->getType())->getElementType()->getPrimitiveSizeInBits();
1903-
int SIMDJsOp0NumElements = 128 / op0->getElementType()->getPrimitiveSizeInBits();
1921+
const int SIMDJsRetNumElements = SIMDNumElements(cast<VectorType>(SVI->getType()));
1922+
const int SIMDJsOp0NumElements = SIMDNumElements(op0);
19041923
bool swizzleA = true;
19051924
bool swizzleB = true;
19061925
for(int i = 0; i < ResultNumElements; ++i) {

0 commit comments

Comments
 (0)