[llvm-branch-commits] [llvm] [AMDGPU][SDAG] DAGCombine PTRADD -> disjoint OR (PR #146075)
Fabian Ritter via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Aug 1 07:36:48 PDT 2025
================
@@ -2766,6 +2766,33 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
}
}
+ // Transform (ptradd a, b) -> (or disjoint a, b) if it is equivalent and if
+ // that transformation can't block an offset folding at any use of the ptradd.
+ // This should be done late, after legalization, so that it doesn't block
+ // other ptradd combines that could enable more offset folding.
+ if (LegalOperations && DAG.haveNoCommonBitsSet(N0, N1)) {
+ bool TransformCanBreakAddrMode = false;
+ if (auto *C = dyn_cast<ConstantSDNode>(N1)) {
+ TargetLoweringBase::AddrMode AM;
+ AM.HasBaseReg = true;
+ AM.BaseOffs = C->getSExtValue();
+ TransformCanBreakAddrMode = any_of(N->users(), [&](SDNode *User) {
+ if (auto *LoadStore = dyn_cast<MemSDNode>(User);
+ LoadStore && LoadStore->getBasePtr().getNode() == N) {
+ unsigned AS = LoadStore->getAddressSpace();
+ EVT AccessVT = LoadStore->getMemoryVT();
+ Type *AccessTy = AccessVT.getTypeForEVT(*DAG.getContext());
+ return TLI.isLegalAddressingMode(DAG.getDataLayout(), AM, AccessTy,
+ AS);
+ }
+ return false;
----------------
ritter-x2a wrote:
I found that the functionality that I would want to extract from both already exists, more generalized, as a separate function, `canFoldInAddressingMode`, so the PR now uses that instead. `reassociationCanBreakAddressingModePattern` should probably also use `canFoldInAddressingMode`.
https://github.com/llvm/llvm-project/pull/146075
More information about the llvm-branch-commits
mailing list