Bug 108095 - powerpc-linux / powerpc64-linux: ICEs when building Linux's arch/powerpc/kernel/align.c (asm goto)
Summary: powerpc-linux / powerpc64-linux: ICEs when building Linux's arch/powerpc/kern...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-14 08:55 UTC by Jan-Benedict Glaw
Modified: 2023-05-03 11:47 UTC (History)
4 users (show)

See Also:
Host:
Target: powerpc64-linux-gcc
Build:
Known to work:
Known to fail: 13.0
Last reconfirmed: 2022-12-14 00:00:00


Attachments
Minimized testcase (136 bytes, text/plain)
2022-12-14 08:55 UTC, Jan-Benedict Glaw
Details
gcc13-pr108095.patch (1.49 KB, patch)
2022-12-14 13:46 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan-Benedict Glaw 2022-12-14 08:55:38 UTC
Created attachment 54085 [details]
Minimized testcase

For a number of ppc32 builds (using various Linux kernel defconfig configurations) as well as for one 64bit build, I get these:

[mk all 2022-12-11 21:36:22]   powerpc64-linux-gcc -Wp,-MMD,arch/powerpc/kernel/.align.o.d -nostdinc -I./arch/powerpc/include -I./arch/powerpc/include/generated  -I./include -I./arch/powerpc/include/uapi -I./arch/powerpc/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -I ./arch/powerpc -DHAVE_AS_ATHIGH=1 -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu11 -mbig-endian -m64 -msoft-float -pipe -mtraceback=no -mabi=elfv1 -mcall-aixdesc -mcmodel=medium -mno-pointers-to-nested-functions -mcpu=cell -mno-prefixed -mno-pcrel -mno-altivec -mno-vsx -mno-mma -fno-asynchronous-unwind-tables -mno-string -Wa,-maltivec -Wa,-mpower4 -Wa,-many -mabi=elfv1 -mcall-aixdesc -mbig-endian -mstack-protector-guard=tls -mstack-protector-guard-reg=r13 -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -Os -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wno-main -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-dangling-pointer -fomit-frame-pointer -ftrivial-auto-var-init=zero -fno-stack-clash-protection -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-truncation -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -g -mstack-protector-guard-offset=752 -Werror    -DKBUILD_MODFILE='"arch/powerpc/kernel/align"' -DKBUILD_BASENAME='"align"' -DKBUILD_MODNAME='"align"' -D__KBUILD_MODNAME=kmod_align -c -o arch/powerpc/kernel/align.o arch/powerpc/kernel/align.c  
[mk all 2022-12-11 21:36:23] during GIMPLE pass: ccp
[mk all 2022-12-11 21:36:23] arch/powerpc/kernel/align.c: In function '__copy_inst_from_kernel_nofault':
[mk all 2022-12-11 21:36:23] arch/powerpc/kernel/align.c:364:1: internal compiler error: in maybe_register_def, at tree-into-ssa.cc:1948
[mk all 2022-12-11 21:36:23]   364 | }
[mk all 2022-12-11 21:36:23]       | ^
[mk all 2022-12-11 21:36:23] 0x19f12c6 internal_error(char const*, ...)
[mk all 2022-12-11 21:36:23]    ???:0
[mk all 2022-12-11 21:36:23] 0x7be8e0 fancy_abort(char const*, int, char const*)
[mk all 2022-12-11 21:36:23]    ???:0
[mk all 2022-12-11 21:36:23] 0x17a985e dom_walker::walk(basic_block_def*)
[mk all 2022-12-11 21:36:23]    ???:0
[mk all 2022-12-11 21:36:23] 0xe99460 update_ssa(unsigned int)
[mk all 2022-12-11 21:36:23]    ???:0
[mk all 2022-12-11 21:36:23] 0x1041df9 execute_update_addresses_taken()
[mk all 2022-12-11 21:36:23]    ???:0
[mk all 2022-12-11 21:36:23] Please submit a full bug report, with preprocessed source (by using -freport-bug).
[mk all 2022-12-11 21:36:23] Please include the complete backtrace with any bug report.
[mk all 2022-12-11 21:36:23] See <https://gcc.gnu.org/bugs/> for instructions.


This seems to be also an asm goto issue, but it is _not_ fixed with the 7676235f690e624b7e commit. (This issue can still be reproduced with 2dc5d6b1e7e.)

Minimum command line to produce the ICE is: `powerpc64-linux-gcc -Os -g -c -o align.o align.i`. Removing either `-Os` or `-g` silences it.
Comment 1 Martin Liška 2022-12-14 09:45:42 UTC
> 
> This seems to be also an asm goto issue, but it is _not_ fixed with the
> 7676235f690e624b7e commit. (This issue can still be reproduced with
> 2dc5d6b1e7e.)

g:7676235f690e624b7e
g:2dc5d6b1e7e
Comment 2 Martin Liška 2022-12-14 09:51:30 UTC
Confirmed.
Comment 3 Martin Liška 2022-12-14 10:09:04 UTC
Started with r11-5002-ge3b3b59683c1e7, where it was rejected before the revision:

/tmp/ice.i: In function ‘__copy_inst_from_kernel_nofault’:
/tmp/ice.i:5:16: error: expected ‘:’ before string constant
    5 |   asm goto("" : "=r"(*(u32 *)&suffix) : : : Efault);
Comment 4 Jakub Jelinek 2022-12-14 11:36:00 UTC
Slightly cleaned up, ICEs also on x86_64-linux, -Os -g:
int v;
typedef unsigned T;

void
foo (void)
{
  unsigned s;
  asm goto ("" : "=r" (*(T *) &s) : : : lab);
  v = 0;
lab:
}
Comment 5 Jakub Jelinek 2022-12-14 13:46:09 UTC
Created attachment 54090 [details]
gcc13-pr108095.patch

Untested fix.  The addition of phi_nodes check was done because otherwise gsi_insert_on_edge_immediate could split the edge, which is highly undesirable for -fcompare-debug purposes.
Comment 6 Jan-Benedict Glaw 2022-12-14 15:12:27 UTC
I'll give that patch a spin, build the cross-compilers and try to build the affected Linux configurations.
Comment 7 Jan-Benedict Glaw 2022-12-14 17:50:02 UTC
(In reply to Jakub Jelinek from comment #5)
> Created attachment 54090 [details]
> gcc13-pr108095.patch

Compiler builds for me and the ICE went away for all affected Linux configurations. Though I cannot verify whether or not the generated code is correct.
Comment 8 GCC Commits 2022-12-15 08:28:14 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r13-4713-gbf3ce6f84a7a994a0fc87419b383b9ce4efed442
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Dec 15 09:26:44 2022 +0100

    into-ssa: Fix emitting debug stmts after asm goto [PR108095]
    
    The following testcase ICEs, because ccp1 replaced
      s.0_1 = &s;
      __asm__ goto("" : "=r" MEM[(T *)s.0_1] :  :  : "lab" lab);
    with
      __asm__ goto("" : "=r" s :  :  : "lab" lab);
    and because s is no longer addressable, we are rewriting it into
    ssa and want
      __asm__ goto("" : "=r" s_7 :  :  : "lab" lab);
    plus debug stmt
      # DEBUG s => s_7
    The code assumes that there is at most one non-EH edge in that
    case, but with the addition of outputs to asm goto that is no longer the
    case, we can have many outgoing edges.
    
    The patch keeps the checking assertion that there is at most one such
    edge for everything but asm goto, but moves the addition of the debug
    stmt into the loop, so that it can be added on all edges where it is
    possible, not just one of them.
    
    Furthermore, looking at gsi_insert_on_edge_immediate
    -> gimple_find_edge_insert_loc, the conditions to insert stmt there
    to the destination block are
      if (single_pred_p (dest)
          && gimple_seq_empty_p (phi_nodes (dest))
          && dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    (plus there is code to insert it in the previous block but that is
    never true when the pred is known to be stmt_ends_bb_p), while
    mayube_register_def was just checking
                     if (ef && single_pred_p (ef->dest)
                         && ef->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    so if for whatever reason ef->dest had any PHIs, we'd split the
    edge for -g and not for -g0, something we must avoid for -fcompare-debug
    stability.  So, I've added the no phi_nodes check too.
    
    2022-12-15  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/108095
            * tree-into-ssa.cc (maybe_register_def): Insert debug stmt
            on all non-EH edges from asm goto if they have a single
            predecessor rather than asserting there is at most one such edge.
            Test whether there are no PHI nodes next to the single predecessor
            test.
    
            * gcc.dg/pr108095.c: New test.
Comment 9 Jakub Jelinek 2022-12-16 09:24:46 UTC
Fixed on the trunk so far.
Comment 10 GCC Commits 2023-02-10 17:44:26 UTC
The releases/gcc-12 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:7e54e5a2bba69dc7fcbc88fe8cb20c91aaafabd2

commit r12-9126-g7e54e5a2bba69dc7fcbc88fe8cb20c91aaafabd2
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Dec 15 09:26:44 2022 +0100

    into-ssa: Fix emitting debug stmts after asm goto [PR108095]
    
    The following testcase ICEs, because ccp1 replaced
      s.0_1 = &s;
      __asm__ goto("" : "=r" MEM[(T *)s.0_1] :  :  : "lab" lab);
    with
      __asm__ goto("" : "=r" s :  :  : "lab" lab);
    and because s is no longer addressable, we are rewriting it into
    ssa and want
      __asm__ goto("" : "=r" s_7 :  :  : "lab" lab);
    plus debug stmt
      # DEBUG s => s_7
    The code assumes that there is at most one non-EH edge in that
    case, but with the addition of outputs to asm goto that is no longer the
    case, we can have many outgoing edges.
    
    The patch keeps the checking assertion that there is at most one such
    edge for everything but asm goto, but moves the addition of the debug
    stmt into the loop, so that it can be added on all edges where it is
    possible, not just one of them.
    
    Furthermore, looking at gsi_insert_on_edge_immediate
    -> gimple_find_edge_insert_loc, the conditions to insert stmt there
    to the destination block are
      if (single_pred_p (dest)
          && gimple_seq_empty_p (phi_nodes (dest))
          && dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    (plus there is code to insert it in the previous block but that is
    never true when the pred is known to be stmt_ends_bb_p), while
    mayube_register_def was just checking
                     if (ef && single_pred_p (ef->dest)
                         && ef->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    so if for whatever reason ef->dest had any PHIs, we'd split the
    edge for -g and not for -g0, something we must avoid for -fcompare-debug
    stability.  So, I've added the no phi_nodes check too.
    
    2022-12-15  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/108095
            * tree-into-ssa.cc (maybe_register_def): Insert debug stmt
            on all non-EH edges from asm goto if they have a single
            predecessor rather than asserting there is at most one such edge.
            Test whether there are no PHI nodes next to the single predecessor
            test.
    
            * gcc.dg/pr108095.c: New test.
    
    (cherry picked from commit bf3ce6f84a7a994a0fc87419b383b9ce4efed442)
Comment 11 GCC Commits 2023-05-02 20:12:40 UTC
The releases/gcc-11 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:9b580f5d7cb3c23866cdbd19e3c1bfc407e9e9c5

commit r11-10688-g9b580f5d7cb3c23866cdbd19e3c1bfc407e9e9c5
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Dec 15 09:26:44 2022 +0100

    into-ssa: Fix emitting debug stmts after asm goto [PR108095]
    
    The following testcase ICEs, because ccp1 replaced
      s.0_1 = &s;
      __asm__ goto("" : "=r" MEM[(T *)s.0_1] :  :  : "lab" lab);
    with
      __asm__ goto("" : "=r" s :  :  : "lab" lab);
    and because s is no longer addressable, we are rewriting it into
    ssa and want
      __asm__ goto("" : "=r" s_7 :  :  : "lab" lab);
    plus debug stmt
      # DEBUG s => s_7
    The code assumes that there is at most one non-EH edge in that
    case, but with the addition of outputs to asm goto that is no longer the
    case, we can have many outgoing edges.
    
    The patch keeps the checking assertion that there is at most one such
    edge for everything but asm goto, but moves the addition of the debug
    stmt into the loop, so that it can be added on all edges where it is
    possible, not just one of them.
    
    Furthermore, looking at gsi_insert_on_edge_immediate
    -> gimple_find_edge_insert_loc, the conditions to insert stmt there
    to the destination block are
      if (single_pred_p (dest)
          && gimple_seq_empty_p (phi_nodes (dest))
          && dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    (plus there is code to insert it in the previous block but that is
    never true when the pred is known to be stmt_ends_bb_p), while
    mayube_register_def was just checking
                     if (ef && single_pred_p (ef->dest)
                         && ef->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    so if for whatever reason ef->dest had any PHIs, we'd split the
    edge for -g and not for -g0, something we must avoid for -fcompare-debug
    stability.  So, I've added the no phi_nodes check too.
    
    2022-12-15  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/108095
            * tree-into-ssa.c (maybe_register_def): Insert debug stmt
            on all non-EH edges from asm goto if they have a single
            predecessor rather than asserting there is at most one such edge.
            Test whether there are no PHI nodes next to the single predecessor
            test.
    
            * gcc.dg/pr108095.c: New test.
    
    (cherry picked from commit bf3ce6f84a7a994a0fc87419b383b9ce4efed442)
Comment 12 Jakub Jelinek 2023-05-03 11:47:31 UTC
Fixed for 11.4 and 12.3 as well (gcc 10 didn't support asm goto with outputs).