public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7394] match.pd: Further complex simplification fixes [PR104675]
Date: Fri, 25 Feb 2022 20:25:50 +0000 (GMT)	[thread overview]
Message-ID: <20220225202550.677E93858D35@sourceware.org> (raw)

https://gcc.gnu.org/g:f62115c9b770a66c5378f78a2d5866243d560573

commit r12-7394-gf62115c9b770a66c5378f78a2d5866243d560573
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Feb 25 21:25:12 2022 +0100

    match.pd: Further complex simplification fixes [PR104675]
    
    Mark mentioned in the PR further 2 simplifications that also ICE
    with complex types.
    For these, eventually (but IMO GCC 13 materials) we could support it
    for vector types if it would be uniform vector constants.
    Currently integer_pow2p is true only for INTEGER_CSTs and COMPLEX_CSTs
    and we can't use bit_and etc. for complex type.
    
    2022-02-25  Jakub Jelinek  <jakub@redhat.com>
                Marc Glisse  <marc.glisse@inria.fr>
    
            PR tree-optimization/104675
            * match.pd (t * 2U / 2 -> t & (~0 / 2), t / 2U * 2 -> t & ~1):
            Restrict simplifications to INTEGRAL_TYPE_P.
    
            * gcc.dg/pr104675-3.c : New test.

Diff:
---
 gcc/match.pd                      |  4 ++--
 gcc/testsuite/gcc.dg/pr104675-3.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 0bd0ac887e6..97399e580a4 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -731,7 +731,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
 (simplify
  (trunc_div (mult @0 integer_pow2p@1) @1)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
   (bit_and @0 { wide_int_to_tree
 		(type, wi::mask (TYPE_PRECISION (type)
 				 - wi::exact_log2 (wi::to_wide (@1)),
@@ -740,7 +740,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1.  */
 (simplify
  (mult (trunc_div @0 integer_pow2p@1) @1)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
   (bit_and @0 (negate @1))))
 
 /* Simplify (t * 2) / 2) -> t.  */
diff --git a/gcc/testsuite/gcc.dg/pr104675-3.c b/gcc/testsuite/gcc.dg/pr104675-3.c
new file mode 100644
index 00000000000..3b2eb649403
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr104675-3.c
@@ -0,0 +1,29 @@
+/* PR tree-optimization/104675 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+_Complex unsigned int
+foo (_Complex unsigned int x)
+{
+  return (x / 2) * 2;
+}
+
+_Complex unsigned int
+bar (_Complex unsigned int x)
+{
+  return (x * 2) / 2;
+}
+
+_Complex unsigned int
+baz (_Complex unsigned int x)
+{
+  _Complex unsigned int y = x / 2;
+  return y * 2;
+}
+
+_Complex unsigned int
+qux (_Complex unsigned int x)
+{
+  _Complex unsigned int y = x * 2;
+  return y / 2;
+}


                 reply	other threads:[~2022-02-25 20:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220225202550.677E93858D35@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).