[Patch match.pd] Add a simplify rule for x * copysign (1.0, y);

James Greenhalgh james.greenhalgh@arm.com
Thu Oct 1 13:57:00 GMT 2015


Hi,

If it is cheap enough to treat a floating-point value as an integer and
to do bitwise arithmetic on it (as it is for AArch64) we can rewrite:

  x * copysign (1.0, y)

as:

  x ^ (y & (1 << sign_bit_position))

This patch implements that rewriting rule in match.pd, and a testcase
expecting the transform.

This is worth about 6% in 481.wrf for AArch64. I don't don't know enough
about the x86 microarchitectures to know how productive this transformation
is there. In Spec2006FP I didn't see any interesting results in either
direction. Looking at code generation for the testcase I add, I think the
x86 code generation looks worse, but I can't understand why it doesn't use
a vector-side xor and load the mask vector-side. With that fixed up I think
the code generation would look better - though as I say, I'm not an expert
here...

Bootstrapped on both aarch64-none-linux-gnu and x86_64 with no issues.

OK for trunk?

Thanks,
James

---
gcc/

2015-10-01  James Greenhalgh  <james.greenhalgh@arm.com>

	* match.pd (mult (COPYSIGN:s real_onep @0) @1): New simplifier.

gcc/testsuite/

2015-10-01  James Greenhalgh  <james.greenhalgh@arm.com>

	* gcc.dg/tree-ssa/copysign.c: New.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Patch-match.pd-Add-a-simplify-rule-for-x-copysign-1..patch
Type: text/x-patch
Size: 1894 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20151001/b4e6b288/attachment.bin>


More information about the Gcc-patches mailing list