This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] fold a * (a > 0 ? 1 : -1) to abs(a) and related optimizations


Forgot the patch

On Fri, Jun 23, 2017 at 8:59 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> Hi,
>   I saw this on llvm's review site (https://reviews.llvm.org/D34579)
> and I thought why not add it to GCC.  I expanded more than what was
> done on the LLVM patch.
>
> I added the following optimizations:
> Transform X * (X > 0 ? 1 : -1) into ABS(X).
> Transform X * (X >= 0 ? 1 : -1) into ABS(X).
> Transform X * (X > 0.0 ? 1.0 : -1.0) into ABS(X).
> Transform X * (X >= 0.0 ? 1.0 : -1.0) into ABS(X).
> Transform X * (X > 0 ? -1 : 1) into -ABS(X).
> Transform X * (X >= 0 ? -1 : 1) into -ABS(X).
> Transform X * (X > 0.0 ? -1.0 : 1.0) into -ABS(X).
> Transform X * (X >= 0.0 ? -1.0 : 1.0) into -ABS(X).
> Transform X * (X < 0 ? 1 : -1) into -ABS(X).
> Transform X * (X <= 0 ? 1 : -1) into -ABS(X).
> Transform X * (X < 0.0 ? 1.0 : -1.0) into -ABS(X).
> Transform X * (X <= 0.0 ? 1.0 : -1.0) into -ABS(X).
> Transform X * (X < 0 ? -1 : 1) into ABS(X).
> Transform X * (X <= 0 ? -1 : 1) into ABS(X).
> Transform X * (X < 0.0 ? -1.0 : 1.0) into ABS(X).
> Transform X * (X <= 0.0 ? -1.0 : 1.0) into ABS(X).
>
> The floating points ones only happen when not honoring SNANS and not
> honoring signed zeros.
>
> OK?  Bootstrapped and tested on aarch64-linux-gnu with no regressions.
>
> Thanks,
> Andrew Pinski
>
> ChangeLog:
> * match.pd ( X * (X >/>=/</<= 0 ? 1 : -1)): New patterns.
>
> Testsuite/ChangeLog:
> * testsuite/gcc.dg/tree-ssa/mult-abs-1.c: New testcase.
> * testsuite/gcc.dg/tree-ssa/mult-abs-2.c: New testcase.

Attachment: mult-abs.diff.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]