Skip to content

Commit f7b627f

Browse files
committed
Move ptradd -> disjoint OR combine to generic combines
1 parent 425efde commit f7b627f

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
@@ -15144,41 +15144,6 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1514415144
return Folded;
1514515145
}
1514615146

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

0 commit comments

Comments
 (0)