This is an archive of the discontinued LLVM Phabricator instance.

[LibCallSimplifier] use instruction-level fast-math-flags to transform sqrt calls
ClosedPublic

Authored by spatel on Jan 6 2016, 1:44 PM.

Details

Summary

This is a continuation of adding FMF to call instructions:
http://reviews.llvm.org/rL255555

The intent of the patch is to preserve the current behavior of the transform except that we use the sqrt instruction's 'fast' attribute as a trigger rather than the function-level attribute.

But this raises a possible bug noted by the new FIXME comment.

I think that in order to do this transform:
sqrt((x * x) * y) ---> fabs(x) * sqrt(y)

...we need all of the sqrt, the first fmul, and the second fmul to be 'fast'. If any of those ops is strict, we should bail out. Thoughts?

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 44153.Jan 6 2016, 1:44 PM
spatel retitled this revision from to [LibCallSimplifier] use instruction-level fast-math-flags to transform sqrt calls.
spatel updated this object.
spatel added reviewers: davide, scanon, hfinkel.
spatel added a subscriber: llvm-commits.
davide accepted this revision.Jan 11 2016, 10:45 AM
davide edited edge metadata.

This looks fine to me but I'd love to hear Steve's opinion on it. I'm looking forward to see other instructions fixed (pow & friends =))

lib/Transforms/Utils/SimplifyLibCalls.cpp
1425 ↗(On Diff #44153)

I think you're correct that if any of the ops is strict we should bail out, and your code is fine. Have you checked by any chance what GCC does? Steven Canon might have some more opinions on this.

1442 ↗(On Diff #44153)

Spurious blank linke.

This revision is now accepted and ready to land.Jan 11 2016, 10:45 AM
davide added inline comments.Jan 11 2016, 10:48 AM
lib/Transforms/Utils/SimplifyLibCalls.cpp
1442 ↗(On Diff #44153)

Oh I think this one makes sense but please commit the style fix separately.

spatel added inline comments.Jan 11 2016, 11:08 AM
lib/Transforms/Utils/SimplifyLibCalls.cpp
1425 ↗(On Diff #44153)

Based on:
https://gcc.godbolt.org/

I don't think GCC has this optimization. It only matches the simpler case of "sqrt(x * x)".

1442 ↗(On Diff #44153)

Will do.

Thanks for the review!

scanon accepted this revision.Jan 11 2016, 11:32 AM
scanon edited edge metadata.

LGTM.

This revision was automatically updated to reflect the committed changes.