Skip to content

Commit abdc12f

Browse files
committed
Move ptradd -> disjoint OR combine to generic combines
1 parent 36f24e4 commit abdc12f

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
@@ -2774,6 +2774,33 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
27742774
}
27752775
}
27762776

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

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16145,41 +16145,6 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1614516145
return Folded;
1614616146
}
1614716147

16148-
// Transform (ptradd a, b) -> (or disjoint a, b) if it is equivalent and if
16149-
// that transformation can't block an offset folding at any use of the ptradd.
16150-
// This should be done late, after legalization, so that it doesn't block
16151-
// other ptradd combines that could enable more offset folding.
16152-
bool HasIntermediateAssertAlign =
16153-
N0->getOpcode() == ISD::AssertAlign && N0->getOperand(0)->isAnyAdd();
16154-
// This is a hack to work around an ordering problem for DAGs like this:
16155-
// (ptradd (AssertAlign (ptradd p, c1), k), c2)
16156-
// If the outer ptradd is handled first by the DAGCombiner, it can be
16157-
// transformed into a disjoint or. Then, when the generic AssertAlign combine
16158-
// pushes the AssertAlign through the inner ptradd, it's too late for the
16159-
// ptradd reassociation to trigger.
16160-
if (!DCI.isBeforeLegalizeOps() && !HasIntermediateAssertAlign &&
16161-
DAG.haveNoCommonBitsSet(N0, N1)) {
16162-
bool TransformCanBreakAddrMode = any_of(N->users(), [&](SDNode *User) {
16163-
if (auto *LoadStore = dyn_cast<MemSDNode>(User);
16164-
LoadStore && LoadStore->getBasePtr().getNode() == N) {
16165-
unsigned AS = LoadStore->getAddressSpace();
16166-
// Currently, we only really need ptradds to fold offsets into flat
16167-
// memory instructions.
16168-
if (AS != AMDGPUAS::FLAT_ADDRESS)
16169-
return false;
16170-
TargetLoweringBase::AddrMode AM;
16171-
AM.HasBaseReg = true;
16172-
EVT VT = LoadStore->getMemoryVT();
16173-
Type *AccessTy = VT.getTypeForEVT(*DAG.getContext());
16174-
return isLegalAddressingMode(DAG.getDataLayout(), AM, AccessTy, AS);
16175-
}
16176-
return false;
16177-
});
16178-
16179-
if (!TransformCanBreakAddrMode)
16180-
return DAG.getNode(ISD::OR, DL, VT, N0, N1, SDNodeFlags::Disjoint);
16181-
}
16182-
1618316148
if (N1.getOpcode() != ISD::ADD || !N1.hasOneUse())
1618416149
return SDValue();
1618516150

0 commit comments

Comments
 (0)