Skip to content

Commit 44a3786

Browse files
committed
Move ptradd -> disjoint OR combine to generic combines
1 parent 8be2fb1 commit 44a3786

File tree

2 files changed

+27
-35
lines changed

2 files changed

+27
-35
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,6 +2765,33 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
27652765
}
27662766
}
27672767

2768+
// Transform (ptradd a, b) -> (or disjoint a, b) if it is equivalent and if
2769+
// that transformation can't block an offset folding at any use of the ptradd.
2770+
// This should be done late, after legalization, so that it doesn't block
2771+
// other ptradd combines that could enable more offset folding.
2772+
if (LegalOperations && DAG.haveNoCommonBitsSet(N0, N1)) {
2773+
bool TransformCanBreakAddrMode = false;
2774+
if (auto *C = dyn_cast<ConstantSDNode>(N1)) {
2775+
TargetLoweringBase::AddrMode AM;
2776+
AM.HasBaseReg = true;
2777+
AM.BaseOffs = C->getSExtValue();
2778+
TransformCanBreakAddrMode = any_of(N->users(), [&](SDNode *User) {
2779+
if (auto *LoadStore = dyn_cast<MemSDNode>(User);
2780+
LoadStore && LoadStore->getBasePtr().getNode() == N) {
2781+
unsigned AS = LoadStore->getAddressSpace();
2782+
EVT AccessVT = LoadStore->getMemoryVT();
2783+
Type *AccessTy = AccessVT.getTypeForEVT(*DAG.getContext());
2784+
return TLI.isLegalAddressingMode(DAG.getDataLayout(), AM, AccessTy,
2785+
AS);
2786+
}
2787+
return false;
2788+
});
2789+
}
2790+
2791+
if (!TransformCanBreakAddrMode)
2792+
return DAG.getNode(ISD::OR, DL, PtrVT, N0, N1, SDNodeFlags::Disjoint);
2793+
}
2794+
27682795
return SDValue();
27692796
}
27702797

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15236,41 +15236,6 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1523615236
return Folded;
1523715237
}
1523815238

15239-
// Transform (ptradd a, b) -> (or disjoint a, b) if it is equivalent and if
15240-
// that transformation can't block an offset folding at any use of the ptradd.
15241-
// This should be done late, after legalization, so that it doesn't block
15242-
// other ptradd combines that could enable more offset folding.
15243-
bool HasIntermediateAssertAlign =
15244-
N0->getOpcode() == ISD::AssertAlign && N0->getOperand(0)->isAnyAdd();
15245-
// This is a hack to work around an ordering problem for DAGs like this:
15246-
// (ptradd (AssertAlign (ptradd p, c1), k), c2)
15247-
// If the outer ptradd is handled first by the DAGCombiner, it can be
15248-
// transformed into a disjoint or. Then, when the generic AssertAlign combine
15249-
// pushes the AssertAlign through the inner ptradd, it's too late for the
15250-
// ptradd reassociation to trigger.
15251-
if (!DCI.isBeforeLegalizeOps() && !HasIntermediateAssertAlign &&
15252-
DAG.haveNoCommonBitsSet(N0, N1)) {
15253-
bool TransformCanBreakAddrMode = any_of(N->users(), [&](SDNode *User) {
15254-
if (auto *LoadStore = dyn_cast<MemSDNode>(User);
15255-
LoadStore && LoadStore->getBasePtr().getNode() == N) {
15256-
unsigned AS = LoadStore->getAddressSpace();
15257-
// Currently, we only really need ptradds to fold offsets into flat
15258-
// memory instructions.
15259-
if (AS != AMDGPUAS::FLAT_ADDRESS)
15260-
return false;
15261-
TargetLoweringBase::AddrMode AM;
15262-
AM.HasBaseReg = true;
15263-
EVT VT = LoadStore->getMemoryVT();
15264-
Type *AccessTy = VT.getTypeForEVT(*DAG.getContext());
15265-
return isLegalAddressingMode(DAG.getDataLayout(), AM, AccessTy, AS);
15266-
}
15267-
return false;
15268-
});
15269-
15270-
if (!TransformCanBreakAddrMode)
15271-
return DAG.getNode(ISD::OR, DL, VT, N0, N1, SDNodeFlags::Disjoint);
15272-
}
15273-
1527415239
if (N1.getOpcode() != ISD::ADD || !N1.hasOneUse())
1527515240
return SDValue();
1527615241

0 commit comments

Comments
 (0)