[GCC][PATCH][mid-end] Optimize x * copysign (1.0, y) [Patch (1/2)]

Michael Meissner meissner@linux.vnet.ibm.com
Mon Jun 12 19:50:00 GMT 2017


On Mon, Jun 12, 2017 at 07:56:54AM +0000, Tamar Christina wrote:
> Hi All,
> 
> this patch implements a optimization rewriting
> 
> x * copysign (1.0, y) and 
> x * copysign (-1.0, y) 
> 
> to:
> 
> x ^ (y & (1 << sign_bit_position))
> 
> This is done by creating a special builtin during matching and generate the
> appropriate instructions during expand. This new builtin is called XORSIGN.
> 
> The expansion of xorsign depends on if the backend has an appropriate optab
> available. If this is not the case then we use a modified version of the existing
> copysign which does not take the abs value of the first argument as a fall back.
> 
> This patch is a revival of a previous patch
> https://gcc.gnu.org/ml/gcc-patches/2015-10/msg00069.html
> 
> Bootstrapped on both aarch64-none-linux-gnu and x86_64 with no issues.
> Regression done on aarch64-none-linux-gnu and no regressions.
> 
> Ok for trunk?

Please only enable this if you have XORSIGN and XORSIGNF.

On the PowerPC this would involve moving the value from the vector/floating
point registers to the general purpose registers to do the XOR operation and
then back to the vector/floating point registers.

Note, the PowerPC has an instruction that does copysign directly.  It would be
better just to do the copysign/multiply.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797



More information about the Gcc-patches mailing list