public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1654] MATCH: Allow unsigned types for `X & -Y -> X * 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:7ceed7e3e29c3375e3b8c4347d1985a72bbe7f11

commit r14-1654-g7ceed7e3e29c3375e3b8c4347d1985a72bbe7f11
Author: Andrew Pinski <apinski@marvell.com>
Date:   Wed Jun 7 07:58:50 2023 -0700

    MATCH: Allow unsigned types for `X & -Y -> X * Y` pattern
    
    This allows unsigned types if the inner type where the negation is
    located has greater than or equal to precision than the outer type.
    
    branchless-cond.c needs to be updated since now we change it to
    use a multiply rather than still having (-a)&c in there.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu.
    
    gcc/ChangeLog:
    
            * match.pd (`X & -Y -> X * Y`): Allow for truncation
            and the same type for unsigned types.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/branchless-cond.c: Update testcase.

Diff:
---
 gcc/match.pd                                    | 5 ++++-
 gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c | 6 +++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 335e3535184..77030b3b50b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2065,7 +2065,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (if (INTEGRAL_TYPE_P (type)
       && INTEGRAL_TYPE_P (TREE_TYPE (@0))
       && TREE_CODE (TREE_TYPE (@0)) != BOOLEAN_TYPE
-      && !TYPE_UNSIGNED (TREE_TYPE (@0)))
+      /* Sign extending of the neg or a truncation of the neg
+         is needed. */
+      && (!TYPE_UNSIGNED (TREE_TYPE (@0))
+	  || TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0))))
   (mult (convert @0) @1)))
 
 /* Narrow integer multiplication by a zero_one_valued_p operand.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c
index 68087ae6568..e063dc4bb5f 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c
@@ -21,6 +21,6 @@ int f4(unsigned int x, unsigned int y, unsigned int z)
   return ((x & 1) != 0) ? z | y : y;
 }
 
-/* { dg-final { scan-tree-dump-times " -" 4 "optimized" } } */
-/* { dg-final { scan-tree-dump-times " & " 8 "optimized" } } */
-/* { dg-final { scan-tree-dump-not "if" "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \\\*" 4 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " & " 4 "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-1654] MATCH: Allow unsigned types for `X & -Y -> X * 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).