-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[AMDGPU][SDAG] Try folding "lshr i64 + mad" to "mad_u64_u32" #119218
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ebd00b3
[AMDGPU][SDAG] Try folding "lshr i64 + mad" to "mad_[iu]64_[iu]32"
vikramRH 114095c
review comments
vikramRH bfe3fae
review comments
vikramRH a885dfc
update tests
vikramRH 0f4ea1a
review comment
vikramRH b07aea4
simplify code + review comments
vikramRH d3db537
use Lo_32
vikramRH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13857,6 +13857,36 @@ static SDValue getMad64_32(SelectionDAG &DAG, const SDLoc &SL, EVT VT, | |
| return DAG.getNode(ISD::TRUNCATE, SL, VT, Mad); | ||
| } | ||
|
|
||
| // Fold | ||
| // y = lshr i64 x, 32 | ||
| // res = add (mul i64 y, Const), x where "Const" is a 64-bit constant | ||
| // with Const.hi == -1 | ||
| // To | ||
| // res = mad_u64_u32 y.lo ,Const.lo, x.lo | ||
| static SDValue tryFoldMADwithSRL(SelectionDAG &DAG, const SDLoc &SL, | ||
| SDValue MulLHS, SDValue MulRHS, | ||
| SDValue AddRHS) { | ||
|
|
||
| if (MulLHS.getValueType() != MVT::i64 || MulLHS.getOpcode() != ISD::SRL) | ||
| return SDValue(); | ||
|
|
||
| ConstantSDNode *ShiftVal = dyn_cast<ConstantSDNode>(MulLHS.getOperand(1)); | ||
| if (!ShiftVal || MulLHS.getOperand(0) != AddRHS) | ||
| return SDValue(); | ||
|
|
||
| if (ShiftVal->getAsZExtVal() != 32) | ||
| return SDValue(); | ||
|
|
||
| uint64_t Const = dyn_cast<ConstantSDNode>(MulRHS.getNode())->getZExtValue(); | ||
vikramRH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (Hi_32(Const) != -1) | ||
| return SDValue(); | ||
|
|
||
| SDValue ConstMul = DAG.getConstant(Const & 0x00000000FFFFFFFF, SL, MVT::i32); | ||
| return getMad64_32(DAG, SL, MVT::i64, | ||
| DAG.getNode(ISD::TRUNCATE, SL, MVT::i32, MulLHS), ConstMul, | ||
| DAG.getZeroExtendInReg(AddRHS, SL, MVT::i32), false); | ||
| } | ||
|
|
||
| // Fold (add (mul x, y), z) --> (mad_[iu]64_[iu]32 x, y, z) plus high | ||
| // multiplies, if any. | ||
| // | ||
|
|
@@ -13915,6 +13945,14 @@ SDValue SITargetLowering::tryFoldToMad64_32(SDNode *N, | |
| SDValue MulRHS = LHS.getOperand(1); | ||
| SDValue AddRHS = RHS; | ||
|
|
||
| if (isa<ConstantSDNode>(MulLHS) || isa<ConstantSDNode>(MulRHS)) { | ||
| if (MulRHS.getOpcode() == ISD::SRL) | ||
| std::swap(MulLHS, MulRHS); | ||
|
||
|
|
||
| if (SDValue FoldedMAD = tryFoldMADwithSRL(DAG, SL, MulLHS, MulRHS, AddRHS)) | ||
| return FoldedMAD; | ||
| } | ||
|
|
||
| // Always check whether operands are small unsigned values, since that | ||
| // knowledge is useful in more cases. Check for small signed values only if | ||
| // doing so can unlock a shorter code sequence. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you also implement the same in globalisel? Not sure if the original combine is there, or if that needs porting as well
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.
sure, it seems original combine needs porting