Skip to content

[CodeGen] EVT::changeVectorElementType can't handle conversion from simple to extended vector types #171608

@RKSimon

Description

@RKSimon

As discussed here: #171459 (comment)

/// Return a VT for a vector type whose attributes match ourselves
/// with the exception of the element type that is chosen by the caller.
EVT changeVectorElementType(EVT EltVT) const {
if (isSimple()) {
assert(EltVT.isSimple() &&
"Can't change simple vector VT to have extended element VT");
return getSimpleVT().changeVectorElementType(EltVT.getSimpleVT());
}
return changeExtendedVectorElementType(EltVT);
}

The problem is if the original vector was simple (e.g. v512i32) - but you change it to one that isn't (e.g. v512i64) - MVT::changeVectorElementType is called and will assert internally:
/// Return a VT for a vector type whose attributes match ourselves
/// with the exception of the element type that is chosen by the caller.
MVT changeVectorElementType(MVT EltVT) const {
MVT VecTy = MVT::getVectorVT(EltVT, getVectorElementCount());
assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
"Simple vector VT not representable by simple integer vector VT!");
return VecTy;
}

Ideally we'd do something similar to EVT::getVectorVT, check for MVT::INVALID_SIMPLE_VALUE_TYPE and fallback to changeExtendedVectorElementType if necessary.

This would then allow quite a few EVT::getVectorVT uses in DAGCombine etc. to be simplified to call EVT::changeElementType or EVT::changeVectorElementType directly without fear of an assert

Metadata

Metadata

Assignees

Labels

good first issuehttps://github.com/llvm/llvm-project/contributellvm:SelectionDAGSelectionDAGISel as well

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions