-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[AMDGPU][SDAG] Add ISD::PTRADD DAG combines #142739
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
ritter-x2a
merged 7 commits into
main
from
users/ritter-x2a/06-04-_amdgpu_sdag_add_isd_ptradd_dag_combines
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a28fb2f
[AMDGPU][SDAG] Add ISD::PTRADD DAG combines
ritter-x2a 704dd1c
Remove undef/poison operand handling from the PTRADD dag combine
ritter-x2a b5d5466
Bail out early in the generic combine to reduce identation, add a com…
ritter-x2a 654c370
Add an explicit PtrVT == IntVT to the (ptradd 0, x) -> x fold
ritter-x2a bb8a8d7
Add a test for poison/undef folds.
ritter-x2a 49fb4c4
Implement reviewer suggestions
ritter-x2a 61ad2a3
Update new AArch64/cpa-selectiondag.ll test
ritter-x2a 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
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 |
---|---|---|
|
@@ -945,6 +945,7 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM, | |
} | ||
|
||
setTargetDAGCombine({ISD::ADD, | ||
ISD::PTRADD, | ||
ISD::UADDO_CARRY, | ||
ISD::SUB, | ||
ISD::USUBO_CARRY, | ||
|
@@ -15084,6 +15085,49 @@ SDValue SITargetLowering::performAddCombine(SDNode *N, | |
return SDValue(); | ||
} | ||
|
||
SDValue SITargetLowering::performPtrAddCombine(SDNode *N, | ||
DAGCombinerInfo &DCI) const { | ||
SelectionDAG &DAG = DCI.DAG; | ||
SDLoc DL(N); | ||
SDValue N0 = N->getOperand(0); | ||
SDValue N1 = N->getOperand(1); | ||
|
||
if (N1.getOpcode() == ISD::ADD) { | ||
ritter-x2a marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// (ptradd x, (add y, z)) -> (ptradd (ptradd x, y), z) if z is a constant, | ||
// y is not, and (add y, z) is used only once. | ||
// (ptradd x, (add y, z)) -> (ptradd (ptradd x, z), y) if y is a constant, | ||
// z is not, and (add y, z) is used only once. | ||
// The goal is to move constant offsets to the outermost ptradd, to create | ||
// more opportunities to fold offsets into memory instructions. | ||
// Together with the generic combines in DAGCombiner.cpp, this also | ||
// implements (ptradd (ptradd x, y), z) -> (ptradd (ptradd x, z), y)). | ||
// | ||
// This transform is here instead of in the general DAGCombiner as it can | ||
// turn in-bounds pointer arithmetic out-of-bounds, which is problematic for | ||
// AArch64's CPA. | ||
ritter-x2a marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+15105
to
+15107
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. Probably should have a better opt-in mechanism with this in the generic combiner, Can move it later |
||
SDValue X = N0; | ||
SDValue Y = N1.getOperand(0); | ||
SDValue Z = N1.getOperand(1); | ||
if (N1.hasOneUse()) { | ||
bool YIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Y); | ||
bool ZIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Z); | ||
if (ZIsConstant != YIsConstant) { | ||
// If both additions in the original were NUW, the new ones are as well. | ||
SDNodeFlags Flags = | ||
(N->getFlags() & N1->getFlags()) & SDNodeFlags::NoUnsignedWrap; | ||
if (YIsConstant) | ||
std::swap(Y, Z); | ||
|
||
SDValue Inner = DAG.getMemBasePlusOffset(X, Y, DL, Flags); | ||
DCI.AddToWorklist(Inner.getNode()); | ||
return DAG.getMemBasePlusOffset(Inner, Z, DL, Flags); | ||
} | ||
} | ||
} | ||
|
||
return SDValue(); | ||
} | ||
|
||
SDValue SITargetLowering::performSubCombine(SDNode *N, | ||
DAGCombinerInfo &DCI) const { | ||
SelectionDAG &DAG = DCI.DAG; | ||
|
@@ -15622,6 +15666,8 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N, | |
switch (N->getOpcode()) { | ||
case ISD::ADD: | ||
return performAddCombine(N, DCI); | ||
case ISD::PTRADD: | ||
return performPtrAddCombine(N, DCI); | ||
case ISD::SUB: | ||
return performSubCombine(N, DCI); | ||
case ISD::UADDO_CARRY: | ||
|
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.