public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/107115] Wrong codegen from TBAA under stores that change effective type?
Date: Thu, 06 Oct 2022 09:44:52 +0000	[thread overview]
Message-ID: <bug-107115-4-rezUAo9uFY@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107115-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107115

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
So possibly expand_assignment is eliding the store somewhere downthread
(it's operand_equal_p check shouldn't fire).  It's

rtx
store_expr (tree exp, rtx target, int call_param_p,
            bool nontemporal, bool reverse)
{
...
  if ((! rtx_equal_p (temp, target)
       || (temp != target && (side_effects_p (temp)
                              || side_effects_p (target))))

which doesn't fire.  We have

(gdb) p debug_rtx (temp)
(mem:DI (reg/f:DI 87 [ _11 ]) [2 *_11+0 S8 A64])
(gdb) p debug_rtx (target)
(mem:DI (reg/f:DI 87 [ _11 ]) [1 MEM[(long int *)_11]+0 S8 A64])

Note that even just matching up MEM_ALIAS_SET isn't enough.  I'd call the
above optimization premature at least.

(gdb) p mems_same_for_tbaa_p (temp, target)
$13 = false

so

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 80bb1b8a4c5..71a7fc19c42 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -6207,7 +6207,8 @@ store_expr (tree exp, rtx target, int call_param_p,

   if ((! rtx_equal_p (temp, target)
        || (temp != target && (side_effects_p (temp)
-                             || side_effects_p (target))))
+                             || side_effects_p (target)
+                             || !mems_same_for_tbaa_p (temp, target))))
       && TREE_CODE (exp) != ERROR_MARK
       /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
         but TARGET is not valid memory reference, TEMP will differ

fixes this mistake.  But then we run into the sched issue which
-fno-schedule-insns2 "fixes".

  parent reply	other threads:[~2022-10-06  9:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-01 20:00 [Bug middle-end/107115] New: " bugdal at aerifal dot cx
2022-10-01 23:34 ` [Bug rtl-optimization/107115] " pinskia at gcc dot gnu.org
2022-10-01 23:51 ` [Bug middle-end/107115] " pinskia at gcc dot gnu.org
2022-10-06  9:44 ` rguenth at gcc dot gnu.org [this message]
2022-10-06 12:20 ` cvs-commit at gcc dot gnu.org
2022-10-06 12:24 ` rguenth at gcc dot gnu.org
2022-10-06 15:19 ` amonakov at gcc dot gnu.org
2022-10-06 15:32 ` jakub at gcc dot gnu.org
2022-10-06 15:39 ` amonakov at gcc dot gnu.org
2022-10-06 19:04 ` pinskia at gcc dot gnu.org
2022-10-07  7:41 ` rguenth at gcc dot gnu.org
2022-10-07  7:44 ` rguenth at gcc dot gnu.org
2022-10-07 13:19 ` amonakov at gcc dot gnu.org
2022-12-27 22:19 ` gabravier at gmail dot com
2022-12-27 22:21 ` gabravier at gmail dot com

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=bug-107115-4-rezUAo9uFY@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).