@@ -15199,7 +15199,15 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
15199
15199
// Adapted from DAGCombiner::visitADDLikeCommutative.
15200
15200
SDValue V, K;
15201
15201
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);
15203
15211
DCI.AddToWorklist(Inner.getNode());
15204
15212
return DAG.getNode(ISD::SUB, DL, VT, N0, Inner);
15205
15213
}
@@ -15228,8 +15236,7 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
15228
15236
SDValue GAValue = N0.getOperand(0);
15229
15237
if (const GlobalAddressSDNode *GA =
15230
15238
dyn_cast<GlobalAddressSDNode>(GAValue)) {
15231
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
15232
- if (DCI.isBeforeLegalizeOps() && TLI.isOffsetFoldingLegal(GA)) {
15239
+ if (DCI.isBeforeLegalizeOps() && isOffsetFoldingLegal(GA)) {
15233
15240
// If both additions in the original were NUW, reassociation preserves
15234
15241
// that.
15235
15242
SDNodeFlags Flags =
0 commit comments