Skip to content

Commit f74fee4

Browse files
committed
[SelectionDAG] Fix a false assumption that there will always be a valid integer type corresponding to a vector type
`SelectionDAG::getBitcastedAnyExtOrTrunc` assumes that there is always a valid integer type corresponding to another type, which is not always true when it comes to vector type. For example, `<3 x i8>` doesn't have a corresponding integer type. Fix SWDEV-464698.
1 parent 5d15f60 commit f74fee4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,13 +1468,31 @@ SDValue SelectionDAG::getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
14681468
}
14691469

14701470
SDValue SelectionDAG::getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL,
1471-
EVT VT) {
1471+
EVT VT) {
14721472
assert(!VT.isVector());
14731473
auto Type = Op.getValueType();
14741474
SDValue DestOp;
14751475
if (Type == VT)
14761476
return Op;
14771477
auto Size = Op.getValueSizeInBits();
1478+
auto IntTy = MVT::getIntegerVT(Size);
1479+
1480+
if (!IntTy.isValid()) {
1481+
// We assume integers of "weird" size have already been legalized here.
1482+
assert(Type.isVector());
1483+
unsigned NumElements = Type.getVectorNumElements();
1484+
unsigned ExtSize = VT.getScalarSizeInBits();
1485+
EVT ElementType = Type.getVectorElementType();
1486+
unsigned ExtNumElements = ExtSize / ElementType.getScalarSizeInBits();
1487+
assert(NumElements < ExtNumElements);
1488+
MVT ExtType = MVT::getVectorVT(ElementType.getSimpleVT(), ExtNumElements);
1489+
SmallVector<SDValue, 4> Ops(ExtNumElements, getUNDEF(ElementType));
1490+
SDValue ExtVec = getNode(ISD::BUILD_VECTOR, DL, ExtType, Ops);
1491+
DestOp = getNode(ISD::INSERT_SUBVECTOR, DL, ExtType, ExtVec, Op,
1492+
getVectorIdxConstant(0, DL));
1493+
return getBitcast(VT, DestOp);
1494+
}
1495+
14781496
DestOp = getBitcast(MVT::getIntegerVT(Size), Op);
14791497
if (DestOp.getValueType() == VT)
14801498
return DestOp;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 %s -o -
2+
3+
define void @no_corresponding_integer_type(i8 %arg, ptr addrspace(1) %ptr) {
4+
entry:
5+
%load = load <3 x i8>, ptr addrspace(1) %ptr, align 1
6+
%elt0 = extractelement <3 x i8> %load, i64 0
7+
%mul0 = mul i8 %elt0, %arg
8+
%or = or i8 %mul0, 1
9+
%mul1 = mul i8 %arg, %arg
10+
%add = add i8 %mul1, %or
11+
store i8 %add, ptr addrspace(1) %ptr, align 1
12+
ret void
13+
}

0 commit comments

Comments
 (0)