@@ -13171,20 +13171,39 @@ static SDValue tryToFoldExtOfExtload(SelectionDAG &DAG, DAGCombiner &Combiner,
13171
13171
13172
13172
// fold ([s|z]ext (load x)) -> ([s|z]ext (truncate ([s|z]extload x)))
13173
13173
// Only generate vector extloads when 1) they're legal, and 2) they are
13174
- // deemed desirable by the target.
13174
+ // deemed desirable by the target. NonNegZExt can be set to true if a zero
13175
+ // extend has the nonneg flag to allow use of sextload if profitable.
13175
13176
static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
13176
13177
const TargetLowering &TLI, EVT VT,
13177
13178
bool LegalOperations, SDNode *N, SDValue N0,
13178
13179
ISD::LoadExtType ExtLoadType,
13179
- ISD::NodeType ExtOpc) {
13180
+ ISD::NodeType ExtOpc,
13181
+ bool NonNegZExt = false) {
13182
+ if (!ISD::isNON_EXTLoad(N0.getNode()) || !ISD::isUNINDEXEDLoad(N0.getNode()))
13183
+ return {};
13184
+
13185
+ // If this is zext nneg, see if it would make sense to treat it as a sext.
13186
+ if (NonNegZExt) {
13187
+ assert(ExtLoadType == ISD::ZEXTLOAD && ExtOpc == ISD::ZERO_EXTEND &&
13188
+ "Unexpected load type or opcode");
13189
+ for (SDNode *User : N0->uses()) {
13190
+ if (User->getOpcode() == ISD::SETCC) {
13191
+ ISD::CondCode CC = cast<CondCodeSDNode>(User->getOperand(2))->get();
13192
+ if (ISD::isSignedIntSetCC(CC)) {
13193
+ ExtLoadType = ISD::SEXTLOAD;
13194
+ ExtOpc = ISD::SIGN_EXTEND;
13195
+ break;
13196
+ }
13197
+ }
13198
+ }
13199
+ }
13200
+
13180
13201
// TODO: isFixedLengthVector() should be removed and any negative effects on
13181
13202
// code generation being the result of that target's implementation of
13182
13203
// isVectorLoadExtDesirable().
13183
- if (!ISD::isNON_EXTLoad(N0.getNode()) ||
13184
- !ISD::isUNINDEXEDLoad(N0.getNode()) ||
13185
- ((LegalOperations || VT.isFixedLengthVector() ||
13186
- !cast<LoadSDNode>(N0)->isSimple()) &&
13187
- !TLI.isLoadExtLegal(ExtLoadType, VT, N0.getValueType())))
13204
+ if ((LegalOperations || VT.isFixedLengthVector() ||
13205
+ !cast<LoadSDNode>(N0)->isSimple()) &&
13206
+ !TLI.isLoadExtLegal(ExtLoadType, VT, N0.getValueType()))
13188
13207
return {};
13189
13208
13190
13209
bool DoXform = true;
@@ -13780,9 +13799,9 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
13780
13799
}
13781
13800
13782
13801
// Try to simplify (zext (load x)).
13783
- if (SDValue foldedExt =
13784
- tryToFoldExtOfLoad( DAG, *this, TLI, VT, LegalOperations, N, N0,
13785
- ISD::ZEXTLOAD, ISD::ZERO_EXTEND ))
13802
+ if (SDValue foldedExt = tryToFoldExtOfLoad(
13803
+ DAG, *this, TLI, VT, LegalOperations, N, N0, ISD::ZEXTLOAD ,
13804
+ ISD::ZERO_EXTEND, N->getFlags().hasNonNeg() ))
13786
13805
return foldedExt;
13787
13806
13788
13807
if (SDValue foldedExt =
0 commit comments