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 tree-optimization/57359] store motion causes wrong code for union access at -O3
Date: Mon, 20 Apr 2020 10:50:04 +0000	[thread overview]
Message-ID: <bug-57359-4-F0KJB7u0EI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57359-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #23 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #22)
> Created attachment 48311 [details]
> patch
> 
> Note that apart from the possible bad impact on optimization when fixing this
> bug an actual fix is complicated by the custom "optimized" dependence
> analysis
> code in the loop invariant motion pass.
> 
> A conservative "simple" patch would be the attached but that doesn't preserve
> store-motion for the following (because the LIM data dependence code doesn't
> care about stmt order):
> 
> typedef int A;
> typedef float B;
> 
> void __attribute__((noinline,noclone))
> foo(A *p, B *q, long unk)
> {
>   for (long i = 0; i < unk; ++i) {
>       q[i] = 42;
>       *p = 1;
>   }
> }
> 
> usually this bug doesn't manifest itself but of course the fix will be
> experienced everywhere.  Benchmarking the simple patch might reveal
> it's not an issue (but I doubt that...).

Which means a better approach might be to, in addition to the existing
dependence testing, verify we can sink the stores through all exits
(IIRC there is/was a similar bug involving ordering of stores sunk where we'd
have to preserve the order).  There's again the difficult cases like

 for ()
  {
    *p = 1;
    q[i] = 42;
    if (test)
      *p = 2; 
  }

which we currently sink as

 for ()
   {
     p_1 = 1;
     q[i] = 42;
     if (test)
       p_1 = 2;
   }
 *p = p_1;

if we want to preserve all sinking we'd have to replay all [possibly
aliased] stores - again more difficult when the store we sink is
in the latch (or when multiple exits are involved).  For the above
example do

  for ()
   {
     p_1 = 1;
     q[i] = 42;
     if (test)
       p_1 = 2;
   }
  *p = p_1;
  q[i] = 42;
  if (test)
    *p = p_1;

with scanning for valid re-orderings starting from all exits we want
to consider sinking two stores that cannot be reordered.

Or we want to re-think the whole store-motion data dependence code.

  parent reply	other threads:[~2020-04-20 10:50 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-21 18:20 [Bug rtl-optimization/57359] New: wrong code for union access at -O3 on x86_64-linux dhazeghi at yahoo dot com
2013-05-21 18:26 ` [Bug rtl-optimization/57359] " pinskia at gcc dot gnu.org
2013-05-21 18:33 ` jakub at gcc dot gnu.org
2013-05-23 19:51 ` dhazeghi at yahoo dot com
2013-05-29 21:14 ` dhazeghi at yahoo dot com
2013-05-30  7:13 ` jakub at gcc dot gnu.org
2013-05-31  8:48 ` rguenth at gcc dot gnu.org
2013-05-31 16:32 ` dhazeghi at yahoo dot com
2013-05-31 21:07 ` joseph at codesourcery dot com
2013-06-03 19:15 ` dhazeghi at yahoo dot com
2013-06-04 12:37 ` [Bug tree-optimization/57359] " rguenth at gcc dot gnu.org
2020-04-20  7:15 ` [Bug tree-optimization/57359] store motion causes wrong code for union access at -O3 rguenth at gcc dot gnu.org
2020-04-20  8:57 ` rguenth at gcc dot gnu.org
2020-04-20 10:50 ` rguenth at gcc dot gnu.org [this message]
2020-04-20 12:03 ` rguenth at gcc dot gnu.org
2020-04-20 12:34 ` pascal_cuoq at hotmail dot com
2020-04-20 12:39 ` rguenther at suse dot de
2020-04-21  7:22 ` rguenth at gcc dot gnu.org
2020-04-27  9:17 ` rguenth at gcc dot gnu.org
2020-04-27  9:35 ` rguenth at gcc dot gnu.org
2020-04-27 12:48 ` rguenth at gcc dot gnu.org
2020-04-30 12:25 ` rguenth at gcc dot gnu.org
2020-05-07 10:12 ` cvs-commit at gcc dot gnu.org
2020-05-07 10:13 ` rguenth at gcc dot gnu.org
2020-05-11 12:56 ` rguenth at gcc dot gnu.org
2020-05-11 12:56 ` rguenth at gcc dot gnu.org
2020-05-11 14:53 ` rguenth at gcc dot gnu.org
2020-05-11 14:57 ` rguenth at gcc dot gnu.org
2020-05-12  6:26 ` rguenth at gcc dot gnu.org
2020-05-12 11:53 ` ro at gcc dot gnu.org
2020-05-12 12:13 ` rguenth at gcc dot gnu.org
2020-05-18  9:50 ` rguenth at gcc dot gnu.org
2020-06-11 15:55 ` pinskia at gcc dot gnu.org

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-57359-4-F0KJB7u0EI@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).