public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-8693] tree-optimization/113630 - invalid code hoisting
Date: Mon,  6 May 2024 13:15:07 +0000 (GMT)	[thread overview]
Message-ID: <20240506131507.274293858D35@sourceware.org> (raw)

https://gcc.gnu.org/g:47cd06042237bf2d4f05b8355362bc038f6fa445

commit r13-8693-g47cd06042237bf2d4f05b8355362bc038f6fa445
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Jan 31 11:28:50 2024 +0100

    tree-optimization/113630 - invalid code hoisting
    
    The following avoids code hoisting (but also PRE insertion) of
    expressions that got value-numbered to another one that are not
    a valid replacement (but still compute the same value).  This time
    because the access path ends in a structure with different size,
    meaning we consider a related access as not trapping because of the
    size of the base of the access.
    
            PR tree-optimization/113630
            * tree-ssa-pre.cc (compute_avail): Avoid registering a
            reference with a representation with not matching base
            access size.
    
            * gcc.dg/torture/pr113630.c: New testcase.
    
    (cherry picked from commit 724b64304ff5c8ac08a913509afd6fde38d7b767)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr113630.c |  4 ++++
 gcc/tree-ssa-pre.cc                     | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr113630.c b/gcc/testsuite/gcc.dg/torture/pr113630.c
new file mode 100644
index 00000000000..72ebdefae27
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr113630.c
@@ -0,0 +1,4 @@
+/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */
+/* { dg-additional-options "-fno-strict-aliasing" } */
+
+#include "pr110799.c"
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index dfcc9ec4711..9e9a2f9d26a 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -4224,6 +4224,20 @@ compute_avail (function *fun)
 			      = wide_int_to_tree (ptr_type_node,
 						  wi::to_wide (ref1->op2));
 			}
+		      /* We also need to make sure that the access path
+			 ends in an access of the same size as otherwise
+			 we might assume an access may not trap while in
+			 fact it might.  That's independent of whether
+			 TBAA is in effect.  */
+		      if (TYPE_SIZE (ref1->type) != TYPE_SIZE (ref2->type)
+			  && (! TYPE_SIZE (ref1->type)
+			      || ! TYPE_SIZE (ref2->type)
+			      || ! operand_equal_p (TYPE_SIZE (ref1->type),
+						    TYPE_SIZE (ref2->type))))
+			{
+			  operands.release ();
+			  continue;
+			}
 		      operands.release ();
 
 		      result = get_or_alloc_expr_for_reference

                 reply	other threads:[~2024-05-06 13:15 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=20240506131507.274293858D35@sourceware.org \
    --to=rguenth@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).