public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH] MATCH: Fix zero_one_valued_p not to match signed 1 bit integers
Date: Fri, 9 Jun 2023 10:27:53 -0700	[thread overview]
Message-ID: <20230609172753.3164342-1-apinski@marvell.com> (raw)

So for the attached testcase, we assumed that zero_one_valued_p would
be the value [0,1] but currently zero_one_valued_p matches also
signed 1 bit integers.
This changes that not to match that and fixes the 2 new testcases at
all optimization levels.

OK for GCC 13? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

	PR tree-optimization/110165
	PR tree-optimization/110166

gcc/ChangeLog:

	* match.pd (zero_one_valued_p): Don't accept
	signed 1-bit integers.

gcc/testsuite/ChangeLog:

	* gcc.c-torture/execute/pr110165-1.c: New test.
	* gcc.c-torture/execute/pr110166-1.c: New test.

(cherry picked from commit 72e652f3425079259faa4edefe1dc571f72f91e0)
---
 gcc/match.pd                                  | 10 ++++--
 .../gcc.c-torture/execute/pr110165-1.c        | 28 ++++++++++++++++
 .../gcc.c-torture/execute/pr110166-1.c        | 33 +++++++++++++++++++
 3 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110165-1.c
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110166-1.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 995ad98d823..91182448250 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1922,9 +1922,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 (match zero_one_valued_p
  @0
- (if (INTEGRAL_TYPE_P (type) && tree_nonzero_bits (@0) == 1)))
+ (if (INTEGRAL_TYPE_P (type)
+      && (TYPE_UNSIGNED (type)
+	  || TYPE_PRECISION (type) > 1)
+      && tree_nonzero_bits (@0) == 1)))
 (match zero_one_valued_p
- truth_valued_p@0)
+ truth_valued_p@0
+ (if (INTEGRAL_TYPE_P (type)
+      && (TYPE_UNSIGNED (type)
+	  || TYPE_PRECISION (type) > 1))))
 
 /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }.  */
 (simplify
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110165-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110165-1.c
new file mode 100644
index 00000000000..9521a19428e
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr110165-1.c
@@ -0,0 +1,28 @@
+struct s
+{
+  int t : 1;
+};
+
+int f(struct s t, int a, int b) __attribute__((noinline));
+int f(struct s t, int a, int b)
+{
+        int bd = t.t;
+        if (bd) a|=b;
+        return a;
+}
+
+int main(void)
+{
+        struct s t;
+        for(int i = -1;i <= 1; i++)
+        {
+                int a = 0x10;
+                int b = 0x0f;
+                int c = a | b;
+		struct s t = {i};
+                int r = f(t, a, b);
+                int exp = (i != 0) ? a | b : a;
+                if (exp != r)
+                 __builtin_abort();
+        }
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110166-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110166-1.c
new file mode 100644
index 00000000000..f999d47fe69
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr110166-1.c
@@ -0,0 +1,33 @@
+struct s
+{
+  int t : 1;
+  int t1 : 1;
+};
+
+int f(struct s t) __attribute__((noinline));
+int f(struct s t)
+{
+   int c = t.t;
+   int d = t.t1;
+   if (c > d)
+     t.t = d;
+   else
+     t.t = c;
+  return t.t;
+}
+
+int main(void)
+{
+        struct s t;
+        for(int i = -1;i <= 0; i++)
+        {
+          for(int j = -1;j <= 0; j++)
+          {
+		struct s t = {i, j};
+                int r = f(t);
+                int exp = i < j ? i : j;
+                if (exp != r)
+                 __builtin_abort();
+          }
+        }
+}
-- 
2.31.1


             reply	other threads:[~2023-06-09 17:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09 17:27 Andrew Pinski [this message]
2023-06-09 21:44 ` Jeff Law
  -- strict thread matches above, loose matches on Subject: below --
2023-06-09  1:47 Andrew Pinski
2023-06-09  9:06 ` Richard Biener
2023-06-09  9:11   ` Jakub Jelinek

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