This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] reassociate fsub+fsub into fsub+fadd
ClosedPublic

Authored by spatel on Jan 10 2020, 9:58 AM.

Details

Summary

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.

Diff Detail

Event Timeline

spatel created this revision.Jan 10 2020, 9:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2020, 9:58 AM
mcberg2017 accepted this revision.Jan 14 2020, 12:45 PM

Looked at this internally for us and looks ok. LGTM.

This revision is now accepted and ready to land.Jan 14 2020, 12:45 PM
This revision was automatically updated to reflect the committed changes.