[PATCH] D72521: [InstCombine] reassociate fsub+fsub into fsub+fadd

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 10:03:12 PST 2020


spatel created this revision.
spatel added reviewers: cameron.mcinally, mcberg2017, ZaMaZaN4iK, arsenm.
Herald added subscribers: hiraditya, wdng, mcrosier.
Herald added a project: LLVM.

As discussed in the motivating PR44509:
https://bugs.llvm.org/show_bug.cgi?id=44509

...we can end up with worse code using fast-math than without. This is because the reassociate pass greedily transforms fsub into fneg/fadd and apparently (based on the regression tests seen here) expects instcombine to clean that up if it wasn't profitable. But we were missing this fold:

  (X - Y) - Z --> X - (Y + Z)

There's another, more specific case that I think we should handle as shown in the "fake" fneg test (but missed with a real fneg), but that's another patch. That may be tricky to get right without conflicting with existing transforms for fneg.


https://reviews.llvm.org/D72521

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/test/Transforms/InstCombine/fsub.ll
  llvm/test/Transforms/Reassociate/fast-SubReassociate.ll
  llvm/test/Transforms/Reassociate/fast-basictest.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72521.237366.patch
Type: text/x-patch
Size: 5593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200110/752cd6d5/attachment.bin>


More information about the llvm-commits mailing list