Skip to content

Commit

Permalink
[DAGCombine][AArch64] Allow transformable to legal vectors to be used…
Browse files Browse the repository at this point in the history
… for MULH lowering.

It looks like it is still profitable to accept a transformable to a legal vector
type, not just a legal vector, as long as vector elements are the same between
two of those types.

Differential Revision: https://reviews.llvm.org/D148229
  • Loading branch information
dtemirbulatov committed Apr 19, 2023
1 parent 89d2785 commit e609687
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 509 deletions.
15 changes: 12 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Expand Up @@ -9939,9 +9939,18 @@ static SDValue combineShiftToMULH(SDNode *N, SelectionDAG &DAG,
// we use mulhs. Othewise, zero extends (zext) use mulhu.
unsigned MulhOpcode = IsSignExt ? ISD::MULHS : ISD::MULHU;

// Combine to mulh if mulh is legal/custom for the narrow type on the target.
if (!TLI.isOperationLegalOrCustom(MulhOpcode, NarrowVT))
return SDValue();
// 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.
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))
return SDValue();
}

SDValue Result =
DAG.getNode(MulhOpcode, DL, NarrowVT, LeftOp.getOperand(0), MulhRightOp);
Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Expand Up @@ -1556,6 +1556,8 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
setOperationAction(ISD::VECREDUCE_AND, VT, Custom);
setOperationAction(ISD::VECREDUCE_OR, VT, Custom);
setOperationAction(ISD::VECREDUCE_XOR, VT, Custom);
setOperationAction(ISD::MULHS, VT, Custom);
setOperationAction(ISD::MULHU, VT, Custom);
}


Expand Down Expand Up @@ -22668,6 +22670,16 @@ void AArch64TargetLowering::ReplaceNodeResults(
case AArch64ISD::UMAXV:
ReplaceReductionResults(N, Results, DAG, ISD::UMAX, AArch64ISD::UMAXV);
return;
case ISD::MULHS:
if (useSVEForFixedLengthVectorVT(SDValue(N, 0).getValueType()))
Results.push_back(
LowerToPredicatedOp(SDValue(N, 0), DAG, AArch64ISD::MULHS_PRED));
return;
case ISD::MULHU:
if (useSVEForFixedLengthVectorVT(SDValue(N, 0).getValueType()))
Results.push_back(
LowerToPredicatedOp(SDValue(N, 0), DAG, AArch64ISD::MULHU_PRED));
return;
case ISD::FP_TO_UINT:
case ISD::FP_TO_SINT:
case ISD::STRICT_FP_TO_SINT:
Expand Down

0 comments on commit e609687

Please sign in to comment.