Bug 110420 - [12/13 Regression] internal compiler error: in gimple_redirect_edge_and_branch due to simple_dce_from_worklist removing `asm goto`
Summary: [12/13 Regression] internal compiler error: in gimple_redirect_edge_and_branc...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 12.4
Assignee: Andrew Pinski
URL: https://gcc.gnu.org/pipermail/gcc-pat...
Keywords: ice-on-valid-code, inline-asm, patch
Depends on:
Blocks:
 
Reported: 2023-06-26 22:15 UTC by Jan-Benedict Glaw
Modified: 2023-06-27 17:24 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 11.1.0, 11.4.0, 12.3.1, 13.1.1, 14.0
Known to fail: 12.1.0
Last reconfirmed: 2023-06-26 00:00:00


Attachments
Preprocessed input. (184.26 KB, application/gzip)
2023-06-26 22:15 UTC, Jan-Benedict Glaw
Details
Patch (307 bytes, patch)
2023-06-26 23:54 UTC, Andrew Pinski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan-Benedict Glaw 2023-06-26 22:15:14 UTC
Created attachment 55400 [details]
Preprocessed input.

Starting with g:21e2ef2dc, I see a new ICE building a PPC Linux kernel for the adder875_defconfig config (see eg. http://toolchain.lug-owl.de/laminar/jobs/linux-powerpc-adder875_defconfig/100):

[mk all 2023-06-26 02:31:11] # CC      arch/powerpc/kernel/ptrace/ptrace-view.o
[mk all 2023-06-26 02:31:11]   powerpc-linux-gcc -Wp,-MMD,arch/powerpc/kernel/ptrace/.ptrace-view.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 -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 -funsigned-char -std=gnu11 -mbig-endian -m32 -msoft-float -pipe -ffixed-r2 -mmultiple -mno-readonly-in-sdata -mcpu=860 -mno-prefixed -mno-pcrel -mno-altivec -mno-vsx -mno-mma -fno-asynchronous-unwind-tables -mno-string -mbig-endian -mstack-protector-guard=tls -mstack-protector-guard-reg=r2 -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=1024 -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-array-bounds -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=544 -Werror -DUTS_MACHINE='"ppc"'    -DKBUILD_MODFILE='"arch/powerpc/kernel/ptrace/ptrace-view"' -DKBUILD_BASENAME='"ptrace_view"' -DKBUILD_MODNAME='"ptrace_view"' -D__KBUILD_MODNAME=kmod_ptrace_view -c -o arch/powerpc/kernel/ptrace/ptrace-view.o arch/powerpc/kernel/ptrace/ptrace-view.c  
[mk all 2023-06-26 02:31:13] during GIMPLE pass: pre
[mk all 2023-06-26 02:31:13] arch/powerpc/kernel/ptrace/ptrace-view.c: In function 'gpr32_set_common':
[mk all 2023-06-26 02:31:13] arch/powerpc/kernel/ptrace/ptrace-view.c:649:5: internal compiler error: in gimple_redirect_edge_and_branch, at tree-cfg.cc:6262
[mk all 2023-06-26 02:31:13]   649 | int gpr32_set_common(struct task_struct *target,
[mk all 2023-06-26 02:31:13]       |     ^~~~~~~~~~~~~~~~
[mk all 2023-06-26 02:31:13] 0x1a562a6 internal_error(char const*, ...)
[mk all 2023-06-26 02:31:13] 	???:0
[mk all 2023-06-26 02:31:13] 0x826ea1 fancy_abort(char const*, int, char const*)
[mk all 2023-06-26 02:31:13] 	???:0
[mk all 2023-06-26 02:31:13] 0x9b77c9 redirect_edge_and_branch(edge_def*, basic_block_def*)
[mk all 2023-06-26 02:31:13] 	???:0
[mk all 2023-06-26 02:31:13] 0x9b7e43 split_edge(edge_def*)
[mk all 2023-06-26 02:31:13] 	???:0
[mk all 2023-06-26 02:31:13] 0xee1cc7 split_critical_edges(bool)
[mk all 2023-06-26 02:31:13] 	???:0
[mk all 2023-06-26 02:31:13] Please submit a full bug report, with preprocessed source (by using -freport-bug).
[mk all 2023-06-26 02:31:13] Please include the complete backtrace with any bug report.
[mk all 2023-06-26 02:31:13] See <https://gcc.gnu.org/bugs/> for instructions.
[mk all 2023-06-26 02:31:13] make[4]: *** [scripts/Makefile.build:252: arch/powerpc/kernel/ptrace/ptrace-view.o] Error 1
[mk all 2023-06-26 02:31:13] make[3]: *** [scripts/Makefile.build:494: arch/powerpc/kernel/ptrace] Error 2
[mk all 2023-06-26 02:31:13] make[2]: *** [scripts/Makefile.build:494: arch/powerpc/kernel] Error 2
[mk all 2023-06-26 02:31:13] make[1]: *** [scripts/Makefile.build:494: arch/powerpc] Error 2
[mk all 2023-06-26 02:31:13] make: *** [Makefile:2026: .] Error 2



The full command line is seen above, I'll also attach preprocessed input. (-freport-bug didn't generate something?)
Comment 1 Andrew Pinski 2023-06-26 22:27:25 UTC
Reducing and trying to figure out what is going wrong .
Comment 2 Andrew Pinski 2023-06-26 23:09:57 UTC
Reduced testcase that shows this is a regression in GCC 12+:
```
static int t;
void g(void);

void f(void)
{
  int  __gu_val;
  asm goto(""
     : "=&r"(__gu_val)
     :
     :
     : Efault);
  t = __gu_val;
  g();
Efault:
}

```
simple_dce_from_worklist is removing the statement (in this case during inline but in the original case it was during ccp1 but it was the same issue).

```
Removing statement, writes to write only var:
# .MEM_4 = VDEF <.MEM_3(D)>
t = __gu_val_2;
Removing dead stmt:__asm__ goto("" : "=&r" __gu_val_2 :  :  : "Efault" Efault);
```
Comment 3 Andrew Pinski 2023-06-26 23:34:54 UTC
Note
Comment 4 Andrew Pinski 2023-06-26 23:54:55 UTC
Created attachment 55401 [details]
Patch

So this is another `asm goto` not being considered as volatile.
Anyways that fixes that issue.
Comment 5 Andrew Pinski 2023-06-27 00:10:05 UTC
Mine.
Comment 6 Andrew Pinski 2023-06-27 03:26:31 UTC
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622906.html
Comment 7 Jan-Benedict Glaw 2023-06-27 10:50:41 UTC
Confirmed: This patch fixes the issue for me with the Linux PPC builds.
Comment 8 CVS Commits 2023-06-27 16:28:18 UTC
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:478840a2ca491fbff44371caee4983d1e7b7b7cf

commit r14-2133-g478840a2ca491fbff44371caee4983d1e7b7b7cf
Author: Andrew Pinski <apinski@marvell.com>
Date:   Mon Jun 26 17:14:06 2023 -0700

    Mark asm goto with outputs as volatile
    
    The manual references asm goto as being implicitly volatile already
    and that was done when asm goto could not have outputs. When outputs
    were added to `asm goto`, only asm goto without outputs were still being
    marked as volatile. Now some parts of GCC decide, removing the `asm goto`
    is ok if the output is not used, though not updating the CFG (this happens
    on both the RTL level and the gimple level). Since the biggest user of `asm goto`
    is the Linux kernel and they expect them to be volatile (they use them to
    copy to/from userspace), we should just mark the inline-asm as volatile.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu.
    
            PR middle-end/110420
            PR middle-end/103979
            PR middle-end/98619
    
    gcc/ChangeLog:
    
            * gimplify.cc (gimplify_asm_expr): Mark asm with labels as volatile.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.c-torture/compile/asmgoto-6.c: New test.
Comment 9 Andrew Pinski 2023-06-27 16:29:27 UTC
Fixed in GCC 14 and will be backporting to GCC 12.x and 13.x.
Comment 10 CVS Commits 2023-06-27 16:46:21 UTC
The releases/gcc-13 branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:81fa6dfe1691e93664ef3b4fa66c1e057acea281

commit r13-7484-g81fa6dfe1691e93664ef3b4fa66c1e057acea281
Author: Andrew Pinski <apinski@marvell.com>
Date:   Mon Jun 26 17:14:06 2023 -0700

    Mark asm goto with outputs as volatile
    
    The manual references asm goto as being implicitly volatile already
    and that was done when asm goto could not have outputs. When outputs
    were added to `asm goto`, only asm goto without outputs were still being
    marked as volatile. Now some parts of GCC decide, removing the `asm goto`
    is ok if the output is not used, though not updating the CFG (this happens
    on both the RTL level and the gimple level). Since the biggest user of `asm goto`
    is the Linux kernel and they expect them to be volatile (they use them to
    copy to/from userspace), we should just mark the inline-asm as volatile.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu.
    
            PR middle-end/110420
            PR middle-end/103979
            PR middle-end/98619
    
    gcc/ChangeLog:
    
            * gimplify.cc (gimplify_asm_expr): Mark asm with labels as volatile.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.c-torture/compile/asmgoto-6.c: New test.
    
    (cherry picked from commit 478840a2ca491fbff44371caee4983d1e7b7b7cf)
Comment 11 CVS Commits 2023-06-27 17:21:39 UTC
The releases/gcc-12 branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

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

commit r12-9732-gee3bb7cb5d2ecfc64adcfd61afb390e72cc08661
Author: Andrew Pinski <apinski@marvell.com>
Date:   Mon Jun 26 17:14:06 2023 -0700

    Mark asm goto with outputs as volatile
    
    The manual references asm goto as being implicitly volatile already
    and that was done when asm goto could not have outputs. When outputs
    were added to `asm goto`, only asm goto without outputs were still being
    marked as volatile. Now some parts of GCC decide, removing the `asm goto`
    is ok if the output is not used, though not updating the CFG (this happens
    on both the RTL level and the gimple level). Since the biggest user of `asm goto`
    is the Linux kernel and they expect them to be volatile (they use them to
    copy to/from userspace), we should just mark the inline-asm as volatile.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu.
    
            PR middle-end/110420
            PR middle-end/103979
            PR middle-end/98619
    
    gcc/ChangeLog:
    
            * gimplify.cc (gimplify_asm_expr): Mark asm with labels as volatile.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.c-torture/compile/asmgoto-6.c: New test.
    
    (cherry picked from commit 478840a2ca491fbff44371caee4983d1e7b7b7cf)
Comment 12 Andrew Pinski 2023-06-27 17:24:12 UTC
Fixed.