@@ -13171,20 +13171,39 @@ static SDValue tryToFoldExtOfExtload(SelectionDAG &DAG, DAGCombiner &Combiner,
1317113171
1317213172// fold ([s|z]ext (load x)) -> ([s|z]ext (truncate ([s|z]extload x)))
1317313173// 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.
1317513176static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1317613177 const TargetLowering &TLI, EVT VT,
1317713178 bool LegalOperations, SDNode *N, SDValue N0,
1317813179 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+
1318013201 // TODO: isFixedLengthVector() should be removed and any negative effects on
1318113202 // code generation being the result of that target's implementation of
1318213203 // 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()))
1318813207 return {};
1318913208
1319013209 bool DoXform = true;
@@ -13780,9 +13799,9 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
1378013799 }
1378113800
1378213801 // 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() ))
1378613805 return foldedExt;
1378713806
1378813807 if (SDValue foldedExt =
0 commit comments