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/112307] Segmentation fault with -O1 -fcode-hoisting
Date: Tue, 31 Oct 2023 10:21:08 +0000	[thread overview]
Message-ID: <bug-112307-4-h2HkAQYjjb@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112307-4@http.gcc.gnu.org/bugzilla/>

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jamborm at gcc dot gnu.org

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
There is no actual code-hoisting happening, the only effect of -fcode-hoisting
is that we perform a round of value-numbering which does perform quite a bit
of simplification in the program.  In particular it simplifies
CompositeMesh::Intersections down to just

  <bb 2> [local count: 1073741826]:
  D.72649 ={v} {CLOBBER};
  MEM[(struct optional *)&D.72649 + 8B] ={v} {CLOBBER};
  MEM[(union _Storage *)&D.72649 + 8B] ={v} {CLOBBER};
  MEM[(struct __as_base  &)&<retval>] ={v} {CLOBBER};
  MEM <unsigned char> [(struct Enumerator *)&<retval>] = 1;
  MEM <unsigned char> [(struct Enumerator *)&<retval> + 16B] = 0;
  MEM <struct Intersection *> [(struct Enumerator *)&<retval> + 8B] =
&MEM[(struct __box *)&<retval>]._M_value;
  MEM <unsigned char> [(struct Enumerator *)&<retval> + 16B] = 1;
  <retval>.end_reached_ = 0;
  D.72649 ={v} {CLOBBER(eol)};
  return <retval>;

by optimizing a leading condition:

+  <bb 2> [local count: 1073741826]:
   D.72649 ={v} {CLOBBER};
   MEM[(struct optional *)&D.72649 + 8B] ={v} {CLOBBER};
   MEM[(union _Storage *)&D.72649 + 8B] ={v} {CLOBBER};
   MEM[(struct __as_base  &)&<retval>] ={v} {CLOBBER};
   MEM <unsigned char> [(struct Enumerator *)&<retval>] = 1;
   MEM <unsigned char> [(struct Enumerator *)&<retval> + 16B] = 0;
-  _12 = MEM[(const struct _Optional_base *)&<retval> +
8B]._M_payload.D.71902._M_engaged;
-  if (_12 != 0)
-    goto <bb 4>; [66.00%]
-  else
-    goto <bb 3>; [34.00%]
-
-  <bb 3> [local count: 365072225]:
   MEM <struct Intersection *> [(struct Enumerator *)&<retval> + 8B] =
&MEM[(struct __box *)&<retval>]._M_value;
   MEM <unsigned char> [(struct Enumerator *)&<retval> + 16B] = 1;
-  goto <bb 12>; [100.00%]

the load ligns up exactly with the immediately preceeding store.

A preceeding value-numbering pass still sees

<bb 2> [local count: 1073741824]:
D.72600 ={v} {CLOBBER};
MEM[(struct single_view *)&D.72600] = 1;
MEM[(struct optional *)&D.72600 + 8B] ={v} {CLOBBER};
MEM[(union _Storage *)&D.72600 + 8B] ={v} {CLOBBER};
MEM[(struct _Optional_payload_base *)&D.72600 + 8B]._M_engaged = 0;
MEM[(struct __as_base  &)&<retval>] ={v} {CLOBBER};
<retval>.enumerator_ = D.72600;
_12 = MEM[(const struct _Optional_base *)&<retval> +
8B]._M_payload.D.71853._M_engaged;
if (_12 != 0)

but SRA then wrecks this I think:

Created a replacement for D.72600 offset: 0, size: 8: SR.74D.80925
Created a replacement for D.72600 offset: 128, size: 8: SR.75D.80926
Removing load: <retval>.enumerator_ = D.72600;
...
  <bb 2> [local count: 1073741824]:
  D.72600 ={v} {CLOBBER};
  SR.74_13 = 1;
  MEM[(struct optional *)&D.72600 + 8B] ={v} {CLOBBER};
  MEM[(union _Storage *)&D.72600 + 8B] ={v} {CLOBBER};
  SR.75_68 = 0;
  MEM[(struct __as_base  &)&<retval>] ={v} {CLOBBER};
  MEM <unsigned char> [(struct Enumerator *)&<retval>] = SR.74_13;
  MEM <unsigned char> [(struct Enumerator *)&<retval> + 16B] = SR.75_68;
  _12 = MEM[(const struct _Optional_base *)&<retval> +
8B]._M_payload.D.71853._M_engaged;
  if (_12 != 0)

that's

#1  0x0000000001c186f1 in sra_modify_assign (
    stmt=<gimple_assign 0x7ffff383b1e0>, gsi=0x7fffffffd9d0)
    at /home/rguenther/src/trunk/gcc/tree-sra.cc:4490
4490                  generate_subtree_copies (racc->first_child, lhs,
(gdb) l
4485                  if (dump_file)
4486                    {
4487                      fprintf (dump_file, "Removing load: ");
4488                      print_gimple_stmt (dump_file, stmt, 0);
4489                    }
4490                  generate_subtree_copies (racc->first_child, lhs,
4491                                           racc->offset, 0, 0, gsi,
4492                                           false, false, loc);

note we pass "write" as false here, and 'lacc' is null.  But if we cannot
analyze the LHS I wonder why we haven't disqualified the RHS here?

I'll note that while this does look like a serious issue -fno-tree-sra
fixes that but that doesn't seem to fix the testcase :/

The difference in main() remains though:

@@ -195,9 +305,7 @@
   if (_16 != 0)
     goto <bb 13>; [11.00%]
   else
-    goto <bb 14>; [89.00%]
-
-  <bb 14> [local count: 105119324]:
+    goto <bb 3>; [89.00%]

   <bb 3> [local count: 955247973]:
   _25 = MEM[(const struct _Optional_base *)&intersections +
8B]._M_payload.D.71902._M_engaged;
@@ -261,15 +369,7 @@
   <bb 12> [local count: 955630224]:
   _34 = _26 + 1;
   MEM[(struct Intersection * &)&intersections + 8] = _34;
-  _36 = &MEM <struct EnumeratorRange> [(void *)&intersections + 1B] != _34;
-  _22 = &MEM <struct EnumeratorRange> [(void *)&intersections + 1B] == _34;
-  intersections.end_reached_ = _22;
-  if (&MEM <struct EnumeratorRange> [(void *)&intersections + 1B] == _34)
-    goto <bb 13>; [11.00%]
-  else
-    goto <bb 15>; [89.00%]
-
-  <bb 15> [local count: 850510900]:
+  intersections.end_reached_ = 0;
   goto <bb 3>; [100.00%]

   <bb 13> [local count: 118111600]:

  parent reply	other threads:[~2023-10-31 10:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31  9:39 [Bug c++/112307] New: " raffael at casagrande dot ch
2023-10-31  9:51 ` [Bug tree-optimization/112307] " rguenth at gcc dot gnu.org
2023-10-31 10:21 ` rguenth at gcc dot gnu.org [this message]
2023-10-31 10:43 ` rguenth at gcc dot gnu.org
2024-03-05 11:34 ` rguenth at gcc dot gnu.org
2024-03-05 15:05 ` redi at gcc dot gnu.org
2024-03-05 15:37 ` rguenth at gcc dot gnu.org
2024-03-08 12:58 ` raffael at casagrande dot ch
2024-03-08 14:30 ` redi at gcc dot gnu.org
2024-03-08 14:32 ` redi at gcc dot gnu.org
2024-03-08 15:12 ` raffael at casagrande dot ch

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-112307-4-h2HkAQYjjb@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).