-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[X86] combinePMULH
- combine mulhu
+ srl
#132548
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54021,7 +54021,7 @@ static SDValue combineTruncatedArithmetic(SDNode *N, SelectionDAG &DAG, | |
} | ||
|
||
// Try to form a MULHU or MULHS node by looking for | ||
// (trunc (srl (mul ext, ext), 16)) | ||
// (trunc (srl (mul ext, ext), >= 16)) | ||
// TODO: This is X86 specific because we want to be able to handle wide types | ||
// before type legalization. But we can only do it if the vector will be | ||
// legalized via widening/splitting. Type legalization can't handle promotion | ||
|
@@ -54046,10 +54046,16 @@ static SDValue combinePMULH(SDValue Src, EVT VT, const SDLoc &DL, | |
|
||
// First instruction should be a right shift by 16 of a multiply. | ||
SDValue LHS, RHS; | ||
APInt ShiftAmt; | ||
if (!sd_match(Src, | ||
m_Srl(m_Mul(m_Value(LHS), m_Value(RHS)), m_SpecificInt(16)))) | ||
m_Srl(m_Mul(m_Value(LHS), m_Value(RHS)), m_ConstInt(ShiftAmt)))) | ||
return SDValue(); | ||
|
||
if (ShiftAmt.ult(16)) | ||
return SDValue(); | ||
|
||
APInt AdditionalShift = (ShiftAmt - 16).trunc(16); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to do some testing to see what happens with MULHS - probably limit AdditionalShift != 0 to just the IsUnsigned case for starters? |
||
// Count leading sign/zero bits on both inputs - if there are enough then | ||
// truncation back to vXi16 will be cheap - either as a pack/shuffle | ||
// sequence or using AVX512 truncations. If the inputs are sext/zext then the | ||
|
@@ -54087,15 +54093,19 @@ static SDValue combinePMULH(SDValue Src, EVT VT, const SDLoc &DL, | |
InVT.getSizeInBits() / 16); | ||
SDValue Res = DAG.getNode(ISD::MULHU, DL, BCVT, DAG.getBitcast(BCVT, LHS), | ||
DAG.getBitcast(BCVT, RHS)); | ||
return DAG.getNode(ISD::TRUNCATE, DL, VT, DAG.getBitcast(InVT, Res)); | ||
Res = DAG.getNode(ISD::TRUNCATE, DL, VT, DAG.getBitcast(InVT, Res)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this path tested? |
||
return DAG.getNode(ISD::SRL, DL, VT, Res, | ||
DAG.getConstant(AdditionalShift, DL, VT)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getShiftAmountConstant |
||
} | ||
|
||
// Truncate back to source type. | ||
LHS = DAG.getNode(ISD::TRUNCATE, DL, VT, LHS); | ||
RHS = DAG.getNode(ISD::TRUNCATE, DL, VT, RHS); | ||
|
||
unsigned Opc = IsSigned ? ISD::MULHS : ISD::MULHU; | ||
return DAG.getNode(Opc, DL, VT, LHS, RHS); | ||
SDValue Res = DAG.getNode(Opc, DL, VT, LHS, RHS); | ||
return DAG.getNode(ISD::SRL, DL, VT, Res, | ||
DAG.getConstant(AdditionalShift, DL, VT)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should IsSigned be ISD::SRA? Use getShiftAmountConstant |
||
} | ||
|
||
// Attempt to match PMADDUBSW, which multiplies corresponding unsigned bytes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth checking for
ShiftAmt.uge(InVT.getScalarSizeInBits())
as well?