public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] fold a * (a > 0 ? 1 : -1) to abs(a) and related optimizations
@ 2017-06-24  3:59 Andrew Pinski
  2017-06-24  3:59 ` Andrew Pinski
  2017-06-24  6:50 ` Marc Glisse
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Pinski @ 2017-06-24  3:59 UTC (permalink / raw)
  To: GCC Patches

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-06-26 15:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-24  3:59 [PATCH] fold a * (a > 0 ? 1 : -1) to abs(a) and related optimizations Andrew Pinski
2017-06-24  3:59 ` Andrew Pinski
2017-06-24  6:50 ` Marc Glisse
2017-06-24 18:51   ` Andrew Pinski
2017-06-24 19:47     ` Marc Glisse
2017-06-24 20:53       ` Andrew Pinski
2017-06-26 15:02   ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).