@@ -52131,12 +52131,11 @@ static SDValue combineSignExtendInReg(SDNode *N, SelectionDAG &DAG,
52131
52131
return SDValue();
52132
52132
}
52133
52133
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.
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.
52140
52139
static SDValue promoteExtBeforeAdd(SDNode *Ext, SelectionDAG &DAG,
52141
52140
const X86Subtarget &Subtarget) {
52142
52141
if (Ext->getOpcode() != ISD::SIGN_EXTEND &&
@@ -52148,19 +52147,17 @@ static SDValue promoteExtBeforeAdd(SDNode *Ext, SelectionDAG &DAG,
52148
52147
if (VT != MVT::i64)
52149
52148
return SDValue();
52150
52149
52151
- bool NSW = false, NUW = false;
52150
+ SDValue Add = Ext->getOperand(0);
52151
+ if (Add.getOpcode() != ISD::ADD)
52152
+ return SDValue();
52153
+
52152
52154
bool Sext = Ext->getOpcode() == ISD::SIGN_EXTEND;
52155
+ bool NSW = Add->getFlags().hasNoSignedWrap();
52156
+ bool NUW = Add->getFlags().hasNoUnsignedWrap();
52153
52157
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)))
52158
+ // We need an 'add nsw' feeding into the 'sext' or 'add nuw' feeding
52159
+ // into the 'zext'
52160
+ if ((Sext && !NSW) || (!Sext && !NUW))
52164
52161
return SDValue();
52165
52162
52166
52163
// Having a constant operand to the 'add' ensures that we are not increasing
@@ -52196,7 +52193,7 @@ static SDValue promoteExtBeforeAdd(SDNode *Ext, SelectionDAG &DAG,
52196
52193
SDNodeFlags Flags;
52197
52194
Flags.setNoSignedWrap(NSW);
52198
52195
Flags.setNoUnsignedWrap(NUW);
52199
- return DAG.getNode(AddOpc , SDLoc(Add), VT, NewExt, NewConstant, Flags);
52196
+ return DAG.getNode(ISD::ADD , SDLoc(Add), VT, NewExt, NewConstant, Flags);
52200
52197
}
52201
52198
52202
52199
// If we face {ANY,SIGN,ZERO}_EXTEND that is applied to a CMOV with constant
0 commit comments