Skip to content

Commit 7de803b

Browse files
davemgreenHoney Goyal
authored andcommitted
[DAG] Generate UMULH/SMULH with wider vector types (llvm#170283)
The existing code for generating umulh/smulh was checking that that the getTypeToTransformTo was a LegalOrCustom operation. This only takes a single legalization step though, so if v4i32 was legal, a v8i32 would be transformed but a v16i32 would not. This patch introduces a getLegalTypeToTransformTo that performs getTypeToTransformTo until a legal type is reached. The umulh/smulh code can then use it to check if the final resultant type will be legal.
1 parent 9c34847 commit 7de803b

File tree

3 files changed

+78
-243
lines changed

3 files changed

+78
-243
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,17 @@ class LLVM_ABI TargetLoweringBase {
11741174
return getTypeConversion(Context, VT).second;
11751175
}
11761176

1177+
/// Perform getTypeToTransformTo repeatedly until a legal type is obtained.
1178+
/// Useful for vector operations that might take multiple steps to legalize.
1179+
EVT getLegalTypeToTransformTo(LLVMContext &Context, EVT VT) const {
1180+
EVT LegalVT = getTypeToTransformTo(Context, VT);
1181+
while (LegalVT != VT) {
1182+
VT = LegalVT;
1183+
LegalVT = getTypeToTransformTo(Context, VT);
1184+
}
1185+
return LegalVT;
1186+
}
1187+
11771188
/// For types supported by the target, this is an identity function. For
11781189
/// types that must be expanded (i.e. integer types that are larger than the
11791190
/// largest integer register or illegal floating point types), this returns

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10895,15 +10895,14 @@ static SDValue combineShiftToMULH(SDNode *N, const SDLoc &DL, SelectionDAG &DAG,
1089510895
// Combine to mulh if mulh is legal/custom for the narrow type on the target
1089610896
// or if it is a vector type then we could transform to an acceptable type and
1089710897
// rely on legalization to split/combine the result.
10898+
EVT TransformVT = NarrowVT;
1089810899
if (NarrowVT.isVector()) {
10899-
EVT TransformVT = TLI.getTypeToTransformTo(*DAG.getContext(), NarrowVT);
10900-
if (TransformVT.getVectorElementType() != NarrowVT.getVectorElementType() ||
10901-
!TLI.isOperationLegalOrCustom(MulhOpcode, TransformVT))
10902-
return SDValue();
10903-
} else {
10904-
if (!TLI.isOperationLegalOrCustom(MulhOpcode, NarrowVT))
10900+
TransformVT = TLI.getLegalTypeToTransformTo(*DAG.getContext(), NarrowVT);
10901+
if (TransformVT.getScalarType() != NarrowVT.getScalarType())
1090510902
return SDValue();
1090610903
}
10904+
if (!TLI.isOperationLegalOrCustom(MulhOpcode, TransformVT))
10905+
return SDValue();
1090710906

1090810907
SDValue Result =
1090910908
DAG.getNode(MulhOpcode, DL, NarrowVT, LeftOp.getOperand(0), MulhRightOp);

0 commit comments

Comments
 (0)