public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-935] phiopt: Simplify (X & Y) == X -> (X & ~Y) == 0 even in presence of integral conversions [PR94589]
@ 2021-05-20  7:11 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-05-20  7:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2b536797f7e43c55072a3215735f5833f1d6d218

commit r12-935-g2b536797f7e43c55072a3215735f5833f1d6d218
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu May 20 09:10:38 2021 +0200

    phiopt: Simplify (X & Y) == X -> (X & ~Y) == 0 even in presence of integral conversions [PR94589]
    
    On Wed, May 19, 2021 at 10:15:53AM +0200, Christophe Lyon via Gcc-patches wrote:
    > After this update, the test fails on arm and aarch64: according to the
    > logs, the optimization is still performed 14 times.
    
    Seems this is because
                  if (change
                      && !flag_syntax_only
                      && (load_extend_op (TYPE_MODE (TREE_TYPE (and0)))
                          == ZERO_EXTEND))
                    {
                      tree uns = unsigned_type_for (TREE_TYPE (and0));
                      and0 = fold_convert_loc (loc, uns, and0);
                      and1 = fold_convert_loc (loc, uns, and1);
                    }
    in fold-const.c adds on these targets extra casts that prevent the
    optimizations.
    
    2021-05-20  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/94589
            * match.pd ((X & Y) == X -> (X & ~Y) == 0): Simplify even in presence
            of integral conversions.

Diff:
---
 gcc/match.pd | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index cdb87636951..e01bb7a4080 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4769,6 +4769,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (simplify
   (cmp:c (bit_and:c @0 @1) @0)
   (cmp (bit_and @0 (bit_not! @1)) { build_zero_cst (TREE_TYPE (@0)); }))
+ (simplify
+  (cmp:c (convert@3 (bit_and (convert@2 @0) INTEGER_CST@1)) (convert @0))
+  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+       && INTEGRAL_TYPE_P (TREE_TYPE (@2))
+       && INTEGRAL_TYPE_P (TREE_TYPE (@3))
+       && TYPE_PRECISION (TREE_TYPE (@2)) == TYPE_PRECISION (TREE_TYPE (@0))
+       && TYPE_PRECISION (TREE_TYPE (@3)) > TYPE_PRECISION (TREE_TYPE (@2))
+       && !wi::neg_p (wi::to_wide (@1)))
+   (cmp (bit_and @0 (convert (bit_not @1)))
+	{ build_zero_cst (TREE_TYPE (@0)); })))
 
  /* (X | Y) == Y becomes (X & ~Y) == 0.  */
  (simplify


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

only message in thread, other threads:[~2021-05-20  7:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20  7:11 [gcc r12-935] phiopt: Simplify (X & Y) == X -> (X & ~Y) == 0 even in presence of integral conversions [PR94589] Jakub Jelinek

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