public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1656] Add Plus to the op list of `(zero_one == 0) ? y : z <op> y` pattern
@ 2023-06-09 14:16 Andrew Pinski
  0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-06-09 14:16 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:55fcaa9a8bd9c8ce97ca929fc902c88cf92786a0

commit r14-1656-g55fcaa9a8bd9c8ce97ca929fc902c88cf92786a0
Author: Andrew Pinski <apinski@marvell.com>
Date:   Wed Jun 7 09:05:15 2023 -0700

    Add Plus to the op list of `(zero_one == 0) ? y : z <op> y` pattern
    
    This adds plus to the op list of `(zero_one == 0) ? y : z <op> y` patterns
    which currently has bit_ior and bit_xor.
    This shows up now in GCC after the boolization work that Uroš has been doing.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
    
            PR tree-optimization/97711
            PR tree-optimization/110155
    
    gcc/ChangeLog:
    
            * match.pd ((zero_one == 0) ? y : z <op> y): Add plus to the op.
            ((zero_one != 0) ? z <op> y : y): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/branchless-cond-add-2.c: New test.
            * gcc.dg/tree-ssa/branchless-cond-add.c: New test.

Diff:
---
 gcc/match.pd                                          |  4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c |  8 ++++++++
 gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c   | 18 ++++++++++++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 610668d562c..a17d6838c14 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3696,7 +3696,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (max @2 @1))
 
 /* (zero_one == 0) ? y : z <op> y -> ((typeof(y))zero_one * z) <op> y */
-(for op (bit_xor bit_ior)
+(for op (bit_xor bit_ior plus)
  (simplify
   (cond (eq zero_one_valued_p@0
             integer_zerop)
@@ -3708,7 +3708,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        (op (mult (convert:type @0) @2) @1))))
 
 /* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> y */
-(for op (bit_xor bit_ior)
+(for op (bit_xor bit_ior plus)
  (simplify
   (cond (ne zero_one_valued_p@0
             integer_zerop)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c
new file mode 100644
index 00000000000..27607e10f88
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/97711 */
+
+int f (int x) { return x & 1 ? x - 1 : x; }
+
+/* { dg-final { scan-tree-dump-times " & -2" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "if " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c
new file mode 100644
index 00000000000..0d81c07b03a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/110155 */
+
+int f1(unsigned int x, unsigned int y, unsigned int z)
+{
+  return ((x & 1) == 0) ? y : z + y;
+}
+
+int f2(unsigned int x, unsigned int y, unsigned int z)
+{
+  return ((x & 1) != 0) ? z + y : y;
+}
+
+/* { dg-final { scan-tree-dump-times " \\\*" 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \\\+ " 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " & " 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "if " "optimized" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-09 14:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09 14:16 [gcc r14-1656] Add Plus to the op list of `(zero_one == 0) ? y : z <op> y` pattern Andrew Pinski

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).