Skip to content

Commit f0f708e

Browse files
committed
Move ptradd -> disjoint OR combine to generic combines
1 parent 607f982 commit f0f708e

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
@@ -2766,6 +2766,33 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
27662766
}
27672767
}
27682768

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

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15136,41 +15136,6 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1513615136
return Folded;
1513715137
}
1513815138

15139-
// Transform (ptradd a, b) -> (or disjoint a, b) if it is equivalent and if
15140-
// that transformation can't block an offset folding at any use of the ptradd.
15141-
// This should be done late, after legalization, so that it doesn't block
15142-
// other ptradd combines that could enable more offset folding.
15143-
bool HasIntermediateAssertAlign =
15144-
N0->getOpcode() == ISD::AssertAlign && N0->getOperand(0)->isAnyAdd();
15145-
// This is a hack to work around an ordering problem for DAGs like this:
15146-
// (ptradd (AssertAlign (ptradd p, c1), k), c2)
15147-
// If the outer ptradd is handled first by the DAGCombiner, it can be
15148-
// transformed into a disjoint or. Then, when the generic AssertAlign combine
15149-
// pushes the AssertAlign through the inner ptradd, it's too late for the
15150-
// ptradd reassociation to trigger.
15151-
if (!DCI.isBeforeLegalizeOps() && !HasIntermediateAssertAlign &&
15152-
DAG.haveNoCommonBitsSet(N0, N1)) {
15153-
bool TransformCanBreakAddrMode = any_of(N->users(), [&](SDNode *User) {
15154-
if (auto *LoadStore = dyn_cast<MemSDNode>(User);
15155-
LoadStore && LoadStore->getBasePtr().getNode() == N) {
15156-
unsigned AS = LoadStore->getAddressSpace();
15157-
// Currently, we only really need ptradds to fold offsets into flat
15158-
// memory instructions.
15159-
if (AS != AMDGPUAS::FLAT_ADDRESS)
15160-
return false;
15161-
TargetLoweringBase::AddrMode AM;
15162-
AM.HasBaseReg = true;
15163-
EVT VT = LoadStore->getMemoryVT();
15164-
Type *AccessTy = VT.getTypeForEVT(*DAG.getContext());
15165-
return isLegalAddressingMode(DAG.getDataLayout(), AM, AccessTy, AS);
15166-
}
15167-
return false;
15168-
});
15169-
15170-
if (!TransformCanBreakAddrMode)
15171-
return DAG.getNode(ISD::OR, DL, VT, N0, N1, SDNodeFlags::Disjoint);
15172-
}
15173-
1517415139
if (N1.getOpcode() != ISD::ADD || !N1.hasOneUse())
1517515140
return SDValue();
1517615141

0 commit comments

Comments
 (0)