[PATCH] D62774: [DAGCombine][X86][AArch64][MIPS][LANAI] (C - x) - y -> C - (x + y) fold (PR41952)

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 2 04:43:02 PDT 2019

RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.


Comment at: lib/CodeGen/SelectionDAG/DAGCombiner.cpp:3017
+  // (C - x) - y  ->  C - (x + y)
+  if (N0.hasOneUse() && N0.getOpcode() == ISD::SUB &&
lebedev.ri wrote:
> RKSimon wrote:
> > Do we gain anything from the general case here? This seems to cause a small increase in register pressure in many cases - limit to the (0 - x) - y negation case only?
> Could you please be more specific?
> The only regressions i'm seeing are 32-bit `@reg64_lshr_by_sub_from_negated*`
> The obvious positives are all these newly-formed `neg`
> https://godbolt.org/z/JK0ldm <- which is kinda the endgoal here.
> If we limit this to only hoist `neg` (and this will be the first such restriction
> in all of these patches), then naturally, the `@reg64_lshr_by_sub_from_negated*`
> pattern will no longer produce `neg`, since the `sub 64, %x` will not be sunk.
> That can still be fixed, if we transform `C-X` to `neg(x)+C` or so in DAGCombine,
> I was actually going to look into that, but it looked to not be necessary
> with this patch in it's current form.
Yes I think your right - sorry I was being over cautious! 




More information about the llvm-commits mailing list