From: Andrew Pinski <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH] MATCH: Fix PR 109834, ICE with popcount combined with bswap
Date: Fri, 12 May 2023 20:08:22 -0700 [thread overview]
Message-ID: <20230513030822.1481372-1-apinski@marvell.com> (raw)
After r14-673-gc0dd80e4c4c3, there was a check in the match
patterns which was checking the type is unsigned but
instead of using the type, the patch used the expression.
This adds the needed TREE_TYPE so get the correct answer and don't ICE.
Committed as obvious after a bootstrap/test on x86_64-linux-gnu.
PR tree-optimizion/109834
gcc/ChangeLog:
* match.pd (popcount(bswap(x))->popcount(x)): Fix up unsigned type checking.
(popcount(rotate(x,y))->popcount(x)): Likewise.
gcc/testsuite/ChangeLog:
* gcc.c-torture/compile/pr109834-1.c: New test.
* gcc.dg/tree-ssa/pr109834-1.c: New test.
---
gcc/match.pd | 4 ++--
gcc/testsuite/gcc.c-torture/compile/pr109834-1.c | 4 ++++
gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c | 11 +++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr109834-1.c
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 60b01643be5..3089fe309fd 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7867,7 +7867,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& INTEGRAL_TYPE_P (TREE_TYPE (@1)))
(with { unsigned int prec0 = TYPE_PRECISION (TREE_TYPE (@0));
unsigned int prec1 = TYPE_PRECISION (TREE_TYPE (@1)); }
- (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (@1)))
+ (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (TREE_TYPE (@1))))
(popcount @2)))))))
/* popcount(rotate(X Y)) is popcount(X). */
@@ -7880,7 +7880,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& (GIMPLE || !TREE_SIDE_EFFECTS (@3)))
(with { unsigned int prec0 = TYPE_PRECISION (TREE_TYPE (@0));
unsigned int prec1 = TYPE_PRECISION (TREE_TYPE (@1)); }
- (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (@1)))
+ (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (TREE_TYPE (@1))))
(popcount @2)))))))
/* Canonicalize POPCOUNT(x)&1 as PARITY(X). */
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr109834-1.c b/gcc/testsuite/gcc.c-torture/compile/pr109834-1.c
new file mode 100644
index 00000000000..e6c015249b2
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr109834-1.c
@@ -0,0 +1,4 @@
+int f (char v)
+{
+ return __builtin_popcount((int)__builtin_bswap16(v));
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c
new file mode 100644
index 00000000000..f2af18b0cd0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int f (char v)
+{
+ return __builtin_popcount((int)__builtin_bswap16(v));
+}
+
+/* We should be able to remove the bswap here as it does not matter
+ for the popcount. */
+/* { dg-final { scan-tree-dump-not "bswap" "optimized"} } */
--
2.39.1
reply other threads:[~2023-05-13 3:08 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=20230513030822.1481372-1-apinski@marvell.com \
--to=apinski@marvell.com \
--cc=gcc-patches@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).