Skip to content

Commit 2bf97a8

Browse files
committed
Preserve shl nsw flag, remove unnecessary TLI query
1 parent 0eaaae3 commit 2bf97a8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15199,7 +15199,15 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1519915199
// Adapted from DAGCombiner::visitADDLikeCommutative.
1520015200
SDValue V, K;
1520115201
if (sd_match(N1, m_Shl(m_Neg(m_Value(V)), m_Value(K)))) {
15202-
SDValue Inner = DAG.getNode(ISD::SHL, DL, VT, V, K);
15202+
SDNodeFlags ShlFlags = N1->getFlags();
15203+
// If the original shl is NUW and NSW, the first k+1 bits of 0-v are all 0,
15204+
// so v is either 0 or the first k+1 bits of v are all 1 -> NSW can be
15205+
// preserved.
15206+
SDNodeFlags NewShlFlags =
15207+
ShlFlags.hasNoUnsignedWrap() && ShlFlags.hasNoSignedWrap()
15208+
? SDNodeFlags::NoSignedWrap
15209+
: SDNodeFlags();
15210+
SDValue Inner = DAG.getNode(ISD::SHL, DL, VT, V, K, NewShlFlags);
1520315211
DCI.AddToWorklist(Inner.getNode());
1520415212
return DAG.getNode(ISD::SUB, DL, VT, N0, Inner);
1520515213
}
@@ -15228,8 +15236,7 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1522815236
SDValue GAValue = N0.getOperand(0);
1522915237
if (const GlobalAddressSDNode *GA =
1523015238
dyn_cast<GlobalAddressSDNode>(GAValue)) {
15231-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
15232-
if (DCI.isBeforeLegalizeOps() && TLI.isOffsetFoldingLegal(GA)) {
15239+
if (DCI.isBeforeLegalizeOps() && isOffsetFoldingLegal(GA)) {
1523315240
// If both additions in the original were NUW, reassociation preserves
1523415241
// that.
1523515242
SDNodeFlags Flags =

0 commit comments

Comments
 (0)