This is an archive of the discontinued LLVM Phabricator instance.

Refactor reciprocal square root estimate into target-independent function (part 1).
ClosedPublic

Authored by spatel on Sep 20 2014, 11:57 AM.

Details

Summary

This is purely a plumbing patch. No functional changes intended.

The ultimate goal is to allow targets other than PowerPC (certainly X86 and Aarch64) to turn this:

y = C / sqrt(x)

into:

y = C * rsqrte(x)

using whatever HW magic they can use. See http://llvm.org/bugs/show_bug.cgi?id=20900 .

Currently, this is guarded by unsafe-fp-math, but I'm not sure if that's necessary in all cases.

The first step is to add a target hook for RSQRTE, take the already target-independent code selfishly hoarded by PPC, and put it into DAGCombiner. That's this patch.

Next steps:

  1. The code in DAGCombiner::BuildRSQRTE() should be refactored further, but see note below.
  2. Logic in PPCTargetLowering::BuildRSQRTE() should be hoisted into DAGCombiner.
  3. X86 and AArch64 overrides for TargetLowering.BuildRSQRTE() should be added.

Note: when first creating this patch I accidentally wiped out the FP_EXTEND and FP_ROUND cases...and 'make check' still passed. The existing PPC tests in test/CodeGen/PowerPC/recipest.ll are inadequate. I didn't want to alter this code too much from the existing PPC version and risk screwing up some untested functionality.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 13904.Sep 20 2014, 11:57 AM
spatel retitled this revision from to Refactor reciprocal square root estimate into target-independent function (part 1)..
spatel updated this object.
spatel edited the test plan for this revision. (Show Details)
spatel added reviewers: hfinkel, rengolin, chandlerc.
spatel added subscribers: tycho, Unknown Object (MLST).
chandlerc accepted this revision.Sep 20 2014, 2:46 PM
chandlerc edited edge metadata.

Looks like a trivially good refactoring. Looking forward to the cleanup to the function, I agree it could be better. =]

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7012–7014 ↗(On Diff #13904)

You can make SqrtOp a condition variable now, I fixed SDValue to support this:

if (SDValue SqrtOp = BuildRSQRTE(N))
  return SqrtOp;
This revision is now accepted and ready to land.Sep 20 2014, 2:46 PM
spatel added inline comments.Sep 20 2014, 3:24 PM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7012–7014 ↗(On Diff #13904)

Nice! There's a lot more where that came from...

spatel closed this revision.Sep 21 2014, 8:39 AM
spatel updated this revision to Diff 13910.

Closed by commit rL218219 (authored by @spatel).