This is an archive of the discontinued LLVM Phabricator instance.

[TLI] Rework interface for approximate (r)sqrt and reciprocal.
Needs ReviewPublic

Authored by jlebar on Jan 31 2017, 10:21 PM.

Details

Summary

Previously this had a major gotcha: The interface expected the return value of getSqrtEstimate to be a reciprocal sqrt (even if !Reciprocal), unless we were performing zero iterations of Newton's method, in which case it expected a regular sqrt.

Not only was this confusing, but it meant that basically none of our backends were correct if you passed "reciprocal-estimates"="sqrt:0".

This patch reworks the API to separate out three questions which previously were all squished into getSqrtEstimate:

  • Should we do an estimate at all?
  • If so, how many iterations of Newton's method should we perform to refine our estimate?
  • What's our first approximation of the rsqrt?

Now we have one function which answers the first two questions, and a separate function which answers the third.

We also now have a separate function which we call in the special case when we're doing zero iterations of Newton's method and calculating a plain sqrt, and NVPTX hooks into this.

We made the same changes to the reciprocal estimate functions.

In addition, we reworked the parsing of the reciprocal-estimates metadata flag, which needed some love, and otherwise wasn't compatible with this new scheme.

Event Timeline

jlebar created this revision.Jan 31 2017, 10:21 PM
jlebar edited the summary of this revision. (Show Details)Jan 31 2017, 10:26 PM