@@ -2280,6 +2280,35 @@ SDValue X86DAGToDAGISel::matchIndexRecursively(SDValue N,
2280
2280
}
2281
2281
}
2282
2282
2283
+ // index: zext(add_nuw(x,c)) -> index: zext(x), disp + zext(c)
2284
+ // index: zext(addlike(x,c)) -> index: zext(x), disp + zext(c)
2285
+ // TODO: call matchIndexRecursively(AddSrc) if we won't corrupt sext?
2286
+ if (Opc == ISD::ZERO_EXTEND && !VT.isVector () && N.hasOneUse ()) {
2287
+ SDValue Src = N.getOperand (0 );
2288
+ unsigned SrcOpc = Src.getOpcode ();
2289
+ if (((SrcOpc == ISD::ADD && Src->getFlags ().hasNoUnsignedWrap ()) ||
2290
+ CurDAG->isADDLike (Src)) &&
2291
+ Src.hasOneUse ()) {
2292
+ if (CurDAG->isBaseWithConstantOffset (Src)) {
2293
+ SDValue AddSrc = Src.getOperand (0 );
2294
+ auto *AddVal = cast<ConstantSDNode>(Src.getOperand (1 ));
2295
+ uint64_t Offset = (uint64_t )AddVal->getZExtValue ();
2296
+ if (!foldOffsetIntoAddress (Offset * AM.Scale , AM)) {
2297
+ SDLoc DL (N);
2298
+ SDValue ExtSrc = CurDAG->getNode (Opc, DL, VT, AddSrc);
2299
+ SDValue ExtVal = CurDAG->getConstant (Offset, DL, VT);
2300
+ SDValue ExtAdd = CurDAG->getNode (SrcOpc, DL, VT, ExtSrc, ExtVal);
2301
+ insertDAGNode (*CurDAG, N, ExtSrc);
2302
+ insertDAGNode (*CurDAG, N, ExtVal);
2303
+ insertDAGNode (*CurDAG, N, ExtAdd);
2304
+ CurDAG->ReplaceAllUsesWith (N, ExtAdd);
2305
+ CurDAG->RemoveDeadNode (N.getNode ());
2306
+ return ExtSrc;
2307
+ }
2308
+ }
2309
+ }
2310
+ }
2311
+
2283
2312
// TODO: Handle extensions, shifted masks etc.
2284
2313
return N;
2285
2314
}
0 commit comments