@@ -52131,11 +52131,12 @@ static SDValue combineSignExtendInReg(SDNode *N, SelectionDAG &DAG,
52131
52131
return SDValue();
52132
52132
}
52133
52133
52134
- /// sext(add_nsw(x, C)) --> add(sext(x), C_sext)
52135
- /// zext(add_nuw(x, C)) --> add(zext(x), C_zext)
52136
- /// Promoting a sign/zero extension ahead of a no overflow 'add' exposes
52137
- /// opportunities to combine math ops, use an LEA, or use a complex addressing
52138
- /// mode. This can eliminate extend, add, and shift instructions.
52134
+ /// sext(add_nsw(x, C)) --> add_nsw(sext(x), C_sext)
52135
+ /// zext(add_nuw(x, C)) --> add_nuw(zext(x), C_zext)
52136
+ /// zext(addlike(x, C)) --> add(zext(x), C_zext)
52137
+ /// Promoting a sign/zero extension ahead of a no overflow 'add' or 'addlike'
52138
+ /// exposes opportunities to combine math ops, use an LEA, or use a complex
52139
+ /// addressing mode. This can eliminate extend, add, and shift instructions.
52139
52140
static SDValue promoteExtBeforeAdd(SDNode *Ext, SelectionDAG &DAG,
52140
52141
const X86Subtarget &Subtarget) {
52141
52142
if (Ext->getOpcode() != ISD::SIGN_EXTEND &&
@@ -52147,17 +52148,19 @@ static SDValue promoteExtBeforeAdd(SDNode *Ext, SelectionDAG &DAG,
52147
52148
if (VT != MVT::i64)
52148
52149
return SDValue();
52149
52150
52150
- SDValue Add = Ext->getOperand(0);
52151
- if (Add.getOpcode() != ISD::ADD)
52152
- return SDValue();
52153
-
52151
+ bool NSW = false, NUW = false;
52154
52152
bool Sext = Ext->getOpcode() == ISD::SIGN_EXTEND;
52155
- bool NSW = Add->getFlags().hasNoSignedWrap();
52156
- bool NUW = Add->getFlags().hasNoUnsignedWrap();
52157
52153
52158
- // We need an 'add nsw' feeding into the 'sext' or 'add nuw' feeding
52159
- // into the 'zext'
52160
- if ((Sext && !NSW) || (!Sext && !NUW))
52154
+ SDValue Add = Ext->getOperand(0);
52155
+ unsigned AddOpc = Add->getOpcode();
52156
+ if (AddOpc == ISD::ADD) {
52157
+ NSW = Add->getFlags().hasNoSignedWrap();
52158
+ NUW = Add->getFlags().hasNoUnsignedWrap();
52159
+ // We need an 'add nsw' feeding into the 'sext' or 'add nuw' feeding
52160
+ // into the 'zext'
52161
+ if ((Sext && !NSW) || (!Sext && !NUW))
52162
+ return SDValue();
52163
+ } else if (!(!Sext && DAG.isADDLike(Add)))
52161
52164
return SDValue();
52162
52165
52163
52166
// Having a constant operand to the 'add' ensures that we are not increasing
@@ -52193,7 +52196,7 @@ static SDValue promoteExtBeforeAdd(SDNode *Ext, SelectionDAG &DAG,
52193
52196
SDNodeFlags Flags;
52194
52197
Flags.setNoSignedWrap(NSW);
52195
52198
Flags.setNoUnsignedWrap(NUW);
52196
- return DAG.getNode(ISD::ADD , SDLoc(Add), VT, NewExt, NewConstant, Flags);
52199
+ return DAG.getNode(AddOpc , SDLoc(Add), VT, NewExt, NewConstant, Flags);
52197
52200
}
52198
52201
52199
52202
// If we face {ANY,SIGN,ZERO}_EXTEND that is applied to a CMOV with constant
0 commit comments