]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
MATCH: Allow unsigned types for `X & -Y -> X * Y` pattern
authorAndrew Pinski <apinski@marvell.com>
Wed, 7 Jun 2023 14:58:50 +0000 (07:58 -0700)
committerAndrew Pinski <apinski@marvell.com>
Fri, 9 Jun 2023 14:09:15 +0000 (07:09 -0700)
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.

gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c

index 335e3535184bd2ea5093a5c6c70f2f395c540b20..77030b3b50b9941df7d5dcc48442874e86a73623 100644 (file)
@@ -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.
index 68087ae6568300fd6b2e25cbcf726ea1ae693915..e063dc4bb5fb4145c60494d2be58f2177bdb2809 100644 (file)
@@ -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" } } */