Skip to content

Commit 1fc6f04

Browse files
committed
Move ptradd -> disjoint OR combine to generic combines
1 parent 3b6fa25 commit 1fc6f04

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
@@ -15822,41 +15822,6 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1582215822
return Folded;
1582315823
}
1582415824

15825-
// Transform (ptradd a, b) -> (or disjoint a, b) if it is equivalent and if
15826-
// that transformation can't block an offset folding at any use of the ptradd.
15827-
// This should be done late, after legalization, so that it doesn't block
15828-
// other ptradd combines that could enable more offset folding.
15829-
bool HasIntermediateAssertAlign =
15830-
N0->getOpcode() == ISD::AssertAlign && N0->getOperand(0)->isAnyAdd();
15831-
// This is a hack to work around an ordering problem for DAGs like this:
15832-
// (ptradd (AssertAlign (ptradd p, c1), k), c2)
15833-
// If the outer ptradd is handled first by the DAGCombiner, it can be
15834-
// transformed into a disjoint or. Then, when the generic AssertAlign combine
15835-
// pushes the AssertAlign through the inner ptradd, it's too late for the
15836-
// ptradd reassociation to trigger.
15837-
if (!DCI.isBeforeLegalizeOps() && !HasIntermediateAssertAlign &&
15838-
DAG.haveNoCommonBitsSet(N0, N1)) {
15839-
bool TransformCanBreakAddrMode = any_of(N->users(), [&](SDNode *User) {
15840-
if (auto *LoadStore = dyn_cast<MemSDNode>(User);
15841-
LoadStore && LoadStore->getBasePtr().getNode() == N) {
15842-
unsigned AS = LoadStore->getAddressSpace();
15843-
// Currently, we only really need ptradds to fold offsets into flat
15844-
// memory instructions.
15845-
if (AS != AMDGPUAS::FLAT_ADDRESS)
15846-
return false;
15847-
TargetLoweringBase::AddrMode AM;
15848-
AM.HasBaseReg = true;
15849-
EVT VT = LoadStore->getMemoryVT();
15850-
Type *AccessTy = VT.getTypeForEVT(*DAG.getContext());
15851-
return isLegalAddressingMode(DAG.getDataLayout(), AM, AccessTy, AS);
15852-
}
15853-
return false;
15854-
});
15855-
15856-
if (!TransformCanBreakAddrMode)
15857-
return DAG.getNode(ISD::OR, DL, VT, N0, N1, SDNodeFlags::Disjoint);
15858-
}
15859-
1586015825
if (N1.getOpcode() != ISD::ADD || !N1.hasOneUse())
1586115826
return SDValue();
1586215827

0 commit comments

Comments
 (0)