public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition
@ 2023-06-01 12:58 yancheng.li at foxmail dot com
  2023-06-01 13:13 ` [Bug rtl-optimization/110079] [10/11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: yancheng.li at foxmail dot com @ 2023-06-01 12:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110079
           Summary: ICE with -freorder-blocks-and-partition
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yancheng.li at foxmail dot com
  Target Milestone: ---

When compiling the testacse attached with -S -O2 -freorder-blocks-and-partition
flags, I get the following error: 

// target:aarch64-linux-gnu
// configure:../gcc/configure --prefix=/home/lyc/2022/gcc-trunk/install
--enable-shared --enable-threads=posix --enable-checking=release
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-linker-hash-style=gnu --enable-languages=c --enable-plugin
--enable-initfini-array --disable-libgcj --without-isl --without-cloog
--enable-gnu-indirect-function --build=aarch64-linux-gnu
--with-stage1-ldflags=' -Wl,-z,relro,-z,now' --with-boot-ldflags='
-Wl,-z,relro,-z,now' --disable-bootstrap --with-multilib-list=lp64
// thread model:posix
// gcc version 14.0.0 20230531 (experimental) (GCC)
//
// during RTL pass: outof_cfglayout
// test.c: in function‘d’:
// test.c:12:1: internal compiler error:in fixup_reorder_chain,at
cfgrtl.cc:4029
//    12 | }
//       | ^
// 0x824a97 fixup_reorder_chain
//      ../../gcc/gcc/cfgrtl.cc:4029
// 0x824a97 cfg_layout_finalize()
//      ../../gcc/gcc/cfgrtl.cc:4571
// 0x824d5f execute
//      ../../gcc/gcc/cfgrtl.cc:3753
// Please submit a full bug report, with preprocessed source.
// Please include the complete backtrace with any bug report.

// /home/lyc/2022/gcc-trunk/install/libexec/gcc/aarch64-linux-gnu/14.0.0/cc1
-quiet test.c -quiet -dumpbase test.c -dumpbase-ext .c -mlittle-endian
-mabi=lp64 -O2 -freorder-blocks-and-partition -freport-bug -o - -frandom-seed=0
-fdump-noaddr

# 0 "test.c"
# 0 "<built-in>"
# 0 "<命令行>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<命令行>" 2
# 1 "test.c"
int a;
__attribute__((__cold__)) int b(char *);
void d(void) {
e:
  for (; a;)
    ;
  b("");
  asm goto("" : : : : c);
  asm("");
c:
  goto e;
}

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [10/11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
@ 2023-06-01 13:13 ` pinskia at gcc dot gnu.org
  2023-06-01 13:14 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-01 13:13 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.4.0, 12.2.0, 13.1.0,
                   |                            |8.2.0, 9.5.0
   Target Milestone|---                         |10.5
      Known to work|                            |6.4.0, 7.3.0, 7.5.0
           Keywords|                            |ice-on-valid-code
             Target|                            |aarch64*-*-* riscv*-*-*
            Summary|ICE with                    |[10/11/12/13/14 Regression]
                   |-freorder-blocks-and-partit |ICE with
                   |ion and inline-asm goto     |-freorder-blocks-and-partit
                   |                            |ion and inline-asm goto

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [10/11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
  2023-06-01 13:13 ` [Bug rtl-optimization/110079] [10/11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto pinskia at gcc dot gnu.org
@ 2023-06-01 13:14 ` pinskia at gcc dot gnu.org
  2023-06-02 11:48 ` yancheng.li at foxmail dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-01 13:14 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-06-01
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [10/11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
  2023-06-01 13:13 ` [Bug rtl-optimization/110079] [10/11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto pinskia at gcc dot gnu.org
  2023-06-01 13:14 ` pinskia at gcc dot gnu.org
@ 2023-06-02 11:48 ` yancheng.li at foxmail dot com
  2023-07-07 10:45 ` [Bug rtl-optimization/110079] [11/12/13/14 " rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yancheng.li at foxmail dot com @ 2023-06-02 11:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from yancheng.li at foxmail dot com ---
I want to try to solve this problem, but I am not very familiar with RTL
optimization. Could someone give me some guidance?
For example, is this an omission in the reorder-blocks-and-partition
optimization, or another reason?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
                   ` (2 preceding siblings ...)
  2023-06-02 11:48 ` yancheng.li at foxmail dot com
@ 2023-07-07 10:45 ` rguenth at gcc dot gnu.org
  2024-01-12 14:06 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
                   ` (3 preceding siblings ...)
  2023-07-07 10:45 ` [Bug rtl-optimization/110079] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2024-01-12 14:06 ` rguenth at gcc dot gnu.org
  2024-03-06 18:01 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-12 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
                   ` (4 preceding siblings ...)
  2024-01-12 14:06 ` rguenth at gcc dot gnu.org
@ 2024-03-06 18:01 ` jakub at gcc dot gnu.org
  2024-03-07  9:08 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-06 18:01 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 57636
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57636&action=edit
gcc14-pr110079.patch

Untested fix.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
                   ` (5 preceding siblings ...)
  2024-03-06 18:01 ` jakub at gcc dot gnu.org
@ 2024-03-07  9:08 ` cvs-commit at gcc dot gnu.org
  2024-03-07  9:37 ` [Bug rtl-optimization/110079] [11/12/13 " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-07  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r14-9355-gb209d905f5ce1fa9d76ce634fd54245ff340960b
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 7 10:02:49 2024 +0100

    bb-reorder: Fix -freorder-blocks-and-partition ICEs on aarch64 with asm
goto [PR110079]

    The following testcase ICEs, because fix_crossing_unconditional_branches
    thinks that asm goto is an unconditional jump and removes it, replacing it
    with unconditional jump to one of the labels.
    This doesn't happen on x86 because the function in question isn't invoked
    there at all:
      /* If the architecture does not have unconditional branches that
         can span all of memory, convert crossing unconditional branches
         into indirect jumps.  Since adding an indirect jump also adds
         a new register usage, update the register usage information as
         well.  */
      if (!HAS_LONG_UNCOND_BRANCH)
        fix_crossing_unconditional_branches ();
    I think for the asm goto case, for the non-fallthru edge if any we should
    handle it like any other fallthru (and fix_crossing_unconditional_branches
    doesn't really deal with those, it only looks at explicit branches at the
    end of bbs and we are in cfglayout mode at that point) and for the labels
    we just pass the labels as immediates to the assembly and it is up to the
    user to figure out how to store them/branch to them or whatever they want
to
    do.
    So, the following patch fixes this by not treating asm goto as a simple
    unconditional jump.

    I really think that on the !HAS_LONG_UNCOND_BRANCH targets we have a bug
    somewhere else, where outofcfglayout or whatever should actually create
    those indirect jumps on the crossing edges instead of adding normal
    unconditional jumps, I see e.g. in
    __attribute__((cold)) int bar (char *);
    __attribute__((hot)) int baz (char *);
    void qux (int x) { if (__builtin_expect (!x, 1)) goto l1; bar (""); goto
l1; l1: baz (""); }
    void corge (int x) { if (__builtin_expect (!x, 0)) goto l1; baz (""); l2:
return; l1: bar (""); goto l2; }
    with -O2 -freorder-blocks-and-partition on aarch64 before/after this patch
    just b .L? jumps which I believe are +-32MB, so if .text is larger than
    32MB, it could fail to link, but this patch doesn't address that.

    2024-03-07  Jakub Jelinek  <jakub@redhat.com>

            PR rtl-optimization/110079
            * bb-reorder.cc (fix_crossing_unconditional_branches): Don't adjust
            asm goto.

            * gcc.dg/pr110079.c: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [11/12/13 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
                   ` (6 preceding siblings ...)
  2024-03-07  9:08 ` cvs-commit at gcc dot gnu.org
@ 2024-03-07  9:37 ` jakub at gcc dot gnu.org
  2024-03-15 23:29 ` cvs-commit at gcc dot gnu.org
  2024-03-18 14:41 ` [Bug rtl-optimization/110079] [11/12 " jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-07  9:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13/14 Regression]    |[11/12/13 Regression] ICE
                   |ICE with                    |with
                   |-freorder-blocks-and-partit |-freorder-blocks-and-partit
                   |ion and inline-asm goto     |ion and inline-asm goto

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [11/12/13 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
                   ` (7 preceding siblings ...)
  2024-03-07  9:37 ` [Bug rtl-optimization/110079] [11/12/13 " jakub at gcc dot gnu.org
@ 2024-03-15 23:29 ` cvs-commit at gcc dot gnu.org
  2024-03-18 14:41 ` [Bug rtl-optimization/110079] [11/12 " jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-15 23:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:6b69cbe2c85f0b8f4a5a6b23e257d69275bea182

commit r13-8448-g6b69cbe2c85f0b8f4a5a6b23e257d69275bea182
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 7 10:02:49 2024 +0100

    bb-reorder: Fix -freorder-blocks-and-partition ICEs on aarch64 with asm
goto [PR110079]

    The following testcase ICEs, because fix_crossing_unconditional_branches
    thinks that asm goto is an unconditional jump and removes it, replacing it
    with unconditional jump to one of the labels.
    This doesn't happen on x86 because the function in question isn't invoked
    there at all:
      /* If the architecture does not have unconditional branches that
         can span all of memory, convert crossing unconditional branches
         into indirect jumps.  Since adding an indirect jump also adds
         a new register usage, update the register usage information as
         well.  */
      if (!HAS_LONG_UNCOND_BRANCH)
        fix_crossing_unconditional_branches ();
    I think for the asm goto case, for the non-fallthru edge if any we should
    handle it like any other fallthru (and fix_crossing_unconditional_branches
    doesn't really deal with those, it only looks at explicit branches at the
    end of bbs and we are in cfglayout mode at that point) and for the labels
    we just pass the labels as immediates to the assembly and it is up to the
    user to figure out how to store them/branch to them or whatever they want
to
    do.
    So, the following patch fixes this by not treating asm goto as a simple
    unconditional jump.

    I really think that on the !HAS_LONG_UNCOND_BRANCH targets we have a bug
    somewhere else, where outofcfglayout or whatever should actually create
    those indirect jumps on the crossing edges instead of adding normal
    unconditional jumps, I see e.g. in
    __attribute__((cold)) int bar (char *);
    __attribute__((hot)) int baz (char *);
    void qux (int x) { if (__builtin_expect (!x, 1)) goto l1; bar (""); goto
l1; l1: baz (""); }
    void corge (int x) { if (__builtin_expect (!x, 0)) goto l1; baz (""); l2:
return; l1: bar (""); goto l2; }
    with -O2 -freorder-blocks-and-partition on aarch64 before/after this patch
    just b .L? jumps which I believe are +-32MB, so if .text is larger than
    32MB, it could fail to link, but this patch doesn't address that.

    2024-03-07  Jakub Jelinek  <jakub@redhat.com>

            PR rtl-optimization/110079
            * bb-reorder.cc (fix_crossing_unconditional_branches): Don't adjust
            asm goto.

            * gcc.dg/pr110079.c: New test.

    (cherry picked from commit b209d905f5ce1fa9d76ce634fd54245ff340960b)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/110079] [11/12 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto
  2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
                   ` (8 preceding siblings ...)
  2024-03-15 23:29 ` cvs-commit at gcc dot gnu.org
@ 2024-03-18 14:41 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-18 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13 Regression] ICE   |[11/12 Regression] ICE with
                   |with                        |-freorder-blocks-and-partit
                   |-freorder-blocks-and-partit |ion and inline-asm goto
                   |ion and inline-asm goto     |

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 13.3+ too.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-03-18 14:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 12:58 [Bug rtl-optimization/110079] New: ICE with -freorder-blocks-and-partition yancheng.li at foxmail dot com
2023-06-01 13:13 ` [Bug rtl-optimization/110079] [10/11/12/13/14 Regression] ICE with -freorder-blocks-and-partition and inline-asm goto pinskia at gcc dot gnu.org
2023-06-01 13:14 ` pinskia at gcc dot gnu.org
2023-06-02 11:48 ` yancheng.li at foxmail dot com
2023-07-07 10:45 ` [Bug rtl-optimization/110079] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-01-12 14:06 ` rguenth at gcc dot gnu.org
2024-03-06 18:01 ` jakub at gcc dot gnu.org
2024-03-07  9:08 ` cvs-commit at gcc dot gnu.org
2024-03-07  9:37 ` [Bug rtl-optimization/110079] [11/12/13 " jakub at gcc dot gnu.org
2024-03-15 23:29 ` cvs-commit at gcc dot gnu.org
2024-03-18 14:41 ` [Bug rtl-optimization/110079] [11/12 " jakub at gcc dot gnu.org

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).