[llvm] [SelectionDAG] Fix a false assumption that there will always be a valid integer type corresponding to a vector type (PR #96658)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 09:31:17 PDT 2024
================
@@ -1468,13 +1468,31 @@ SDValue SelectionDAG::getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
}
SDValue SelectionDAG::getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL,
- EVT VT) {
+ EVT VT) {
assert(!VT.isVector());
auto Type = Op.getValueType();
SDValue DestOp;
if (Type == VT)
return Op;
auto Size = Op.getValueSizeInBits();
+ auto IntTy = MVT::getIntegerVT(Size);
+
+ if (!IntTy.isValid()) {
+ // We assume integers of "weird" size have already been legalized here.
+ assert(Type.isVector());
+ unsigned NumElements = Type.getVectorNumElements();
+ unsigned ExtSize = VT.getScalarSizeInBits();
+ EVT ElementType = Type.getVectorElementType();
+ unsigned ExtNumElements = ExtSize / ElementType.getScalarSizeInBits();
+ assert(NumElements < ExtNumElements);
+ MVT ExtType = MVT::getVectorVT(ElementType.getSimpleVT(), ExtNumElements);
+ SmallVector<SDValue, 4> Ops(ExtNumElements, getUNDEF(ElementType));
+ SDValue ExtVec = getNode(ISD::BUILD_VECTOR, DL, ExtType, Ops);
----------------
RKSimon wrote:
Why not getUNDEF(ExtType)? If you do need to handle implicit truncation inside the BUILD_VECTOR you can use getSplat / getSplatBuildVector instead.
https://github.com/llvm/llvm-project/pull/96658
More information about the llvm-commits
mailing list