Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,17 @@ class LLVM_ABI TargetLoweringBase {
return getTypeConversion(Context, VT).second;
}

/// Perform getTypeToTransformTo repeatedly until a legal type is obtained.
/// Useful for vector operations that might take multiple steps to legalize.
EVT getLegalTypeToTransformTo(LLVMContext &Context, EVT VT) const {
EVT LegalVT = getTypeToTransformTo(Context, VT);
while (LegalVT != VT) {
VT = LegalVT;
LegalVT = getTypeToTransformTo(Context, VT);
}
return LegalVT;
}

/// For types supported by the target, this is an identity function. For
/// types that must be expanded (i.e. integer types that are larger than the
/// largest integer register or illegal floating point types), this returns
Expand Down
11 changes: 5 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10883,15 +10883,14 @@ static SDValue combineShiftToMULH(SDNode *N, const SDLoc &DL, SelectionDAG &DAG,
// Combine to mulh if mulh is legal/custom for the narrow type on the target
// or if it is a vector type then we could transform to an acceptable type and
// rely on legalization to split/combine the result.
EVT TransformVT = NarrowVT;
if (NarrowVT.isVector()) {
EVT TransformVT = TLI.getTypeToTransformTo(*DAG.getContext(), NarrowVT);
if (TransformVT.getVectorElementType() != NarrowVT.getVectorElementType() ||
!TLI.isOperationLegalOrCustom(MulhOpcode, TransformVT))
return SDValue();
} else {
if (!TLI.isOperationLegalOrCustom(MulhOpcode, NarrowVT))
TransformVT = TLI.getLegalTypeToTransformTo(*DAG.getContext(), NarrowVT);
if (TransformVT.getScalarType() != NarrowVT.getScalarType())
return SDValue();
}
if (!TLI.isOperationLegalOrCustom(MulhOpcode, TransformVT))
return SDValue();

SDValue Result =
DAG.getNode(MulhOpcode, DL, NarrowVT, LeftOp.getOperand(0), MulhRightOp);
Expand Down
Loading
Loading