@@ -15107,7 +15107,15 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
15107
15107
// Adapted from DAGCombiner::visitADDLikeCommutative.
15108
15108
SDValue V, K;
15109
15109
if (sd_match(N1, m_Shl(m_Neg(m_Value(V)), m_Value(K)))) {
15110
- SDValue Inner = DAG.getNode(ISD::SHL, DL, VT, V, K);
15110
+ SDNodeFlags ShlFlags = N1->getFlags();
15111
+ // If the original shl is NUW and NSW, the first k+1 bits of 0-v are all 0,
15112
+ // so v is either 0 or the first k+1 bits of v are all 1 -> NSW can be
15113
+ // preserved.
15114
+ SDNodeFlags NewShlFlags =
15115
+ ShlFlags.hasNoUnsignedWrap() && ShlFlags.hasNoSignedWrap()
15116
+ ? SDNodeFlags::NoSignedWrap
15117
+ : SDNodeFlags();
15118
+ SDValue Inner = DAG.getNode(ISD::SHL, DL, VT, V, K, NewShlFlags);
15111
15119
DCI.AddToWorklist(Inner.getNode());
15112
15120
return DAG.getNode(ISD::SUB, DL, VT, N0, Inner);
15113
15121
}
@@ -15136,8 +15144,7 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
15136
15144
SDValue GAValue = N0.getOperand(0);
15137
15145
if (const GlobalAddressSDNode *GA =
15138
15146
dyn_cast<GlobalAddressSDNode>(GAValue)) {
15139
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
15140
- if (DCI.isBeforeLegalizeOps() && TLI.isOffsetFoldingLegal(GA)) {
15147
+ if (DCI.isBeforeLegalizeOps() && isOffsetFoldingLegal(GA)) {
15141
15148
// If both additions in the original were NUW, reassociation preserves
15142
15149
// that.
15143
15150
SDNodeFlags Flags =
0 commit comments