Skip to content

Commit b79d53c

Browse files
committed
[X86] X86MCInstLower.cpp - printConstant - don't assume the source constant data is smaller than the printed data
Bail out if the constant types aren't compatible Fixes llvm#131389
1 parent ed57ab0 commit b79d53c

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

llvm/lib/Target/X86/X86MCInstLower.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,25 +1582,31 @@ static void printConstant(const Constant *COp, unsigned BitWidth,
15821582
bool IsFP = EltTy->isHalfTy() || EltTy->isFloatTy() || EltTy->isDoubleTy();
15831583
unsigned EltBits = EltTy->getPrimitiveSizeInBits();
15841584
unsigned E = std::min(BitWidth / EltBits, CDS->getNumElements());
1585-
assert((BitWidth % EltBits) == 0 && "Element size mismatch");
1586-
for (unsigned I = 0; I != E; ++I) {
1587-
if (I != 0)
1588-
CS << ",";
1589-
if (IsInteger)
1590-
printConstant(CDS->getElementAsAPInt(I), CS, PrintZero);
1591-
else if (IsFP)
1592-
printConstant(CDS->getElementAsAPFloat(I), CS, PrintZero);
1593-
else
1594-
CS << "?";
1585+
if ((BitWidth % EltBits) == 0) {
1586+
for (unsigned I = 0; I != E; ++I) {
1587+
if (I != 0)
1588+
CS << ",";
1589+
if (IsInteger)
1590+
printConstant(CDS->getElementAsAPInt(I), CS, PrintZero);
1591+
else if (IsFP)
1592+
printConstant(CDS->getElementAsAPFloat(I), CS, PrintZero);
1593+
else
1594+
CS << "?";
1595+
}
1596+
} else {
1597+
CS << "?";
15951598
}
15961599
} else if (auto *CV = dyn_cast<ConstantVector>(COp)) {
15971600
unsigned EltBits = CV->getType()->getScalarSizeInBits();
15981601
unsigned E = std::min(BitWidth / EltBits, CV->getNumOperands());
1599-
assert((BitWidth % EltBits) == 0 && "Element size mismatch");
1600-
for (unsigned I = 0; I != E; ++I) {
1601-
if (I != 0)
1602-
CS << ",";
1603-
printConstant(CV->getOperand(I), EltBits, CS, PrintZero);
1602+
if ((BitWidth % EltBits) == 0) {
1603+
for (unsigned I = 0; I != E; ++I) {
1604+
if (I != 0)
1605+
CS << ",";
1606+
printConstant(CV->getOperand(I), EltBits, CS, PrintZero);
1607+
}
1608+
} else {
1609+
CS << "?";
16041610
}
16051611
} else {
16061612
CS << "?";

llvm/test/CodeGen/X86/pr131389.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s
3+
4+
define void @PR131389(ptr %p) {
5+
; CHECK-LABEL: PR131389:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: movaps {{.*#+}} xmm0 = [0.0E+0,0.0E+0,1.0E+0,0.0E+0]
8+
; CHECK-NEXT: movups %xmm0, (%rax)
9+
; CHECK-NEXT: movss {{.*#+}} xmm0 = [?,?,?,?]
10+
; CHECK-NEXT: movss %xmm0, (%rdi)
11+
; CHECK-NEXT: retq
12+
store <4 x float> <float 0.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00>, ptr poison, align 8
13+
%ld = load <4 x float>, ptr poison, align 8
14+
%elt = extractelement <4 x float> %ld, i64 2
15+
store float %elt, ptr %p, align 4
16+
ret void
17+
}

0 commit comments

Comments
 (0)