This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] exclude x*2.0 from normal negation profitability rules
ClosedPublic

Authored by spatel on Aug 9 2019, 8:40 AM.

Details

Summary

This is the codegen part of fixing:
https://bugs.llvm.org/show_bug.cgi?id=32939

Even with the optimal/canonical IR that is ideally created by D65954, we would reverse that transform in DAGCombiner and end up with the same asm on AArch64 or x86.

I see 2 options for trying to correct this:

  1. Limit isNegatibleForFree() by special-casing the fmul pattern (this patch).
  2. Avoid creating (fmul X, 2.0) in the 1st place by adding a special-case transform to SelectionDAG::getNode() that matches the transform done by DAGCombiner.

This seems like the less intrusive patch, but let me know if there's some other reason to prefer 1 option over the other.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Aug 9 2019, 8:40 AM
cameron.mcinally accepted this revision.Aug 9 2019, 11:25 AM

LGTM. Less invasive is good.

But I do see value in not creating something just to immediately undo it. Option #2 would be similar to the special case in SelectionDAGBuilder::visitFSub(...), which is also good.

I don't have a strong opinion either way...

This revision is now accepted and ready to land.Aug 9 2019, 11:25 AM
This revision was automatically updated to reflect the committed changes.