public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Macleod <amacleod@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-160] Do not fold ADDR_EXPR conditions leading to builtin_unreachable early.
Date: Fri, 21 Apr 2023 20:34:37 +0000 (GMT)	[thread overview]
Message-ID: <20230421203437.23E3A3858D20@sourceware.org> (raw)

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

commit r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Fri Apr 21 15:03:43 2023 -0400

    Do not fold ADDR_EXPR conditions leading to builtin_unreachable early.
    
    Ranges can not represent &var globally yet, so we cannot fold these
    expressions early or we lose the __builtin_unreachable information.
    
            PR tree-optimization/109546
            gcc/
            * tree-vrp.cc (remove_unreachable::remove_and_update_globals): Do
            not fold conditions with ADDR_EXPR early.
    
            gcc/testsuite/
            * gcc.dg/pr109546.c: New.

Diff:
---
 gcc/testsuite/gcc.dg/pr109546.c | 24 ++++++++++++++++++++++++
 gcc/tree-vrp.cc                 |  4 +++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/pr109546.c b/gcc/testsuite/gcc.dg/pr109546.c
new file mode 100644
index 00000000000..ba8af0f31fa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109546.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-optimized" } */
+
+void foo(void);
+static int a, c;
+static int *b = &a;
+static int **d = &b;
+void assert_fail() __attribute__((__noreturn__));
+int main() {
+  int *e = *d;
+  if (e == &a || e == &c);
+  else {
+    __builtin_unreachable();
+  assert_fail();
+  }
+  if (e == &a || e == &c);
+  else
+    foo();
+}
+
+/* { dg-final { scan-tree-dump-not "assert_fail" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */
+
+
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index f4d484526c7..9b870640e23 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -150,7 +150,9 @@ remove_unreachable::remove_and_update_globals (bool final_p)
       // If this is already a constant condition, don't look either
       if (!lhs_p && !rhs_p)
 	continue;
-
+      // Do not remove addresses early. ie if (x == &y)
+      if (!final_p && lhs_p && TREE_CODE (gimple_cond_rhs (s)) == ADDR_EXPR)
+	continue;
       bool dominate_exit_p = true;
       FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name)
 	{

                 reply	other threads:[~2023-04-21 20:34 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=20230421203437.23E3A3858D20@sourceware.org \
    --to=amacleod@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).