This is an archive of the discontinued LLVM Phabricator instance.

Reassociate x + -0.1234 * y into x - 0.1234 * y
ClosedPublic

Authored by erikjv on Aug 14 2014, 4:36 AM.

Details

Summary

This does not require -ffast-math, and it gives CSE/GVN more options to
eliminate duplicate expressions in, e.g.:

return ((x + 0.1234 * y) * (x - 0.1234 * y));

Diff Detail

Repository
rL LLVM

Event Timeline

erikjv updated this revision to Diff 12497.Aug 14 2014, 4:36 AM
erikjv retitled this revision from to Reassociate x + -0.1234 * y into x - 0.1234 * y.
erikjv updated this object.
erikjv edited the test plan for this revision. (Show Details)
erikjv added a subscriber: Unknown Object (MLST).Aug 14 2014, 4:38 AM

This may need to be rebased after r215647.

erikjv updated this revision to Diff 12543.Aug 15 2014, 1:13 AM

Rebased on top of r215647.

Hi Erik,
My suggestions were easier to see in a patch, so see attached. I cleaned
it up a bit then ran it through clang-format. NFCI. If you'd like to
add/edit anything, please do.

Upload the revised patch and I'll review and approve.

Regards,

Chad

Rebased on top of r215647.

http://reviews.llvm.org/D4904

Files:

lib/Target/README.txt
lib/Transforms/Scalar/Reassociate.cpp
test/Transforms/Reassociate/liftsign.ll
erikjv updated this revision to Diff 12664.Aug 19 2014, 8:08 AM

Hi Chad,

I merged in your patch. I also got rid of the "only do it for
non-fast-math". It was bogus, and only there to hide the fact that I
didn't set/copy any math flags to the newly created binop.

mcrosier accepted this revision.Aug 19 2014, 8:40 AM
mcrosier edited edge metadata.

LGTM. Let me know if you need me to push the commit.

Chad

lib/Transforms/Scalar/Reassociate.cpp
1986 ↗(On Diff #12543)

We can be more generic here:
FAdd(x, FMul(-ConstantFP, y)) -> FSub(x, FMul(ConstantFP, y))

I actually prefer

// Reassociate: x + -ConstantFP * y -> x - ConstantFP * y

but I'll let you decide.

This revision is now accepted and ready to land.Aug 19 2014, 8:40 AM
erikjv closed this revision.Aug 21 2014, 3:54 AM
erikjv updated this revision to Diff 12755.

Closed by commit rL216169 (authored by @erikjv).