Bug 86334 - wrong code with -march=athlon -mmemcpy-strategy=libcall:-1:noalign
Summary: wrong code with -march=athlon -mmemcpy-strategy=libcall:-1:noalign
Status: RESOLVED DUPLICATE of bug 88906
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2018-06-27 16:25 UTC by Zdenek Sojka
Modified: 2019-08-30 11:30 UTC (History)
3 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail: 5.5.0, 6.4.1, 7.3.1, 8.1.1, 9.0
Last reconfirmed: 2018-06-28 00:00:00


Attachments
reduced testcase (181 bytes, text/plain)
2018-06-27 16:25 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2018-06-27 16:25:32 UTC
Created attachment 44326 [details]
reduced testcase

Output:
$ i686-pc-linux-gnu-gcc -O -march=athlon -minline-all-stringops -minline-stringops-dynamically -mmemcpy-strategy=libcall:-1:noalign testcase.c
testcase.c: In function 'foo':
testcase.c:5:1: warning: AVX512F vector return without AVX512F enabled changes the ABI [-Wpsabi]
 {
 ^
$ ./a.out 
Aborted

There is missing any initialization of the data -> it contains any garbage just present on the stack.

$ i686-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-i686/bin/i686-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-262017-checking-yes-rtl-df-extra-i686/bin/../libexec/gcc/i686-pc-linux-gnu/9.0.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++ --enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra --with-cloog --with-ppl --with-isl --with-sysroot=/usr/i686-pc-linux-gnu --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i686-pc-linux-gnu --with-ld=/usr/bin/i686-pc-linux-gnu-ld --with-as=/usr/bin/i686-pc-linux-gnu-as --disable-libstdcxx-pch --prefix=/repo/gcc-trunk//binary-trunk-262017-checking-yes-rtl-df-extra-i686
Thread model: posix
gcc version 9.0.0 20180625 (experimental) (GCC)
Comment 1 Uroš Bizjak 2018-06-28 19:51:08 UTC
Confirmed.

For some reason, DSE pass is removing (insn 8) and (insn 9) from the following sequence:

(insn 5 2 6 2 (parallel [
            (set (reg/f:SI 102)
                (plus:SI (reg/f:SI 20 frame)
                    (const_int -128 [0xffffffffffffff80])))
            (clobber (reg:CC 17 flags))
        ]) 231 {*addsi_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))
(insn 6 5 7 2 (set (reg:SI 103)
        (const_int 0 [0])) 86 {*movsi_internal}
     (nil))
(insn 7 6 8 2 (set (reg:SI 104)
        (const_int 16 [0x10])) 86 {*movsi_internal}
     (nil))
(insn 8 7 9 2 (parallel [
            (set (reg:SI 104)
                (const_int 0 [0]))
            (set (reg/f:SI 102)
                (plus:SI (ashift:SI (reg:SI 104)
                        (const_int 2 [0x2]))
                    (reg/f:SI 102)))
            (set (mem/c:BLK (reg/f:SI 102) [1 g+0 S64 A512])
                (const_int 0 [0]))
            (use (reg:SI 103))
            (use (reg:SI 104))
        ]) 1008 {*rep_stossi}
     (expr_list:REG_DEAD (reg:SI 103)
        (expr_list:REG_UNUSED (reg:SI 104)
            (expr_list:REG_UNUSED (reg/f:SI 102)
                (nil)))))
(insn 9 8 12 2 (set (mem/j/c:SI (plus:SI (reg/f:SI 20 frame)
                (const_int -128 [0xffffffffffffff80])) [1 g+0 S4 A512])
        (const_int 4 [0x4])) "pr86334.c":6 86 {*movsi_internal}
     (nil))
(insn 12 9 13 2 (parallel [
            (set (reg/f:SI 107)
                (plus:SI (reg/f:SI 20 frame)
                    (const_int -64 [0xffffffffffffffc0])))
            (clobber (reg:CC 17 flags))
        ]) "pr86334.c":7 231 {*addsi_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))
(insn 13 12 15 2 (parallel [
            (set (reg/f:SI 108)
                (plus:SI (reg/f:SI 20 frame)
                    (const_int -128 [0xffffffffffffff80])))
            (clobber (reg:CC 17 flags))
        ]) "pr86334.c":7 231 {*addsi_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))
(insn 15 13 16 2 (set (mem:SI (plus:SI (reg/f:SI 7 sp)
                (const_int 8 [0x8])) [0  S4 A32])
        (const_int 64 [0x40])) "pr86334.c":7 86 {*movsi_internal}
     (nil))
(insn 16 15 17 2 (set (mem:SI (plus:SI (reg/f:SI 7 sp)
                (const_int 4 [0x4])) [0  S4 A32])
        (reg/f:SI 108)) "pr86334.c":7 86 {*movsi_internal}
     (expr_list:REG_DEAD (reg/f:SI 108)
        (nil)))
(insn 17 16 18 2 (set (mem:SI (reg/f:SI 7 sp) [0  S4 A32])
        (reg/f:SI 107)) "pr86334.c":7 86 {*movsi_internal}
     (expr_list:REG_DEAD (reg/f:SI 107)
        (nil)))
(call_insn 18 17 21 2 (set (reg:SI 0 ax)
        (call (mem:QI (symbol_ref:SI ("memcpy") [flags 0x41]  <function_decl 0x7fda6695c100 __builtin_memcpy>) [0 __builtin_memcpy S1 A8])
            (const_int 12 [0xc]))) "pr86334.c":7 721 {*call_value}
     (expr_list:REG_UNUSED (reg:SI 0 ax)
        (expr_list:REG_EH_REGION (const_int 0 [0])
            (nil)))
    (expr_list:SI (use (mem/f:SI (reg/f:SI 7 sp) [0  S4 A32]))
        (expr_list:SI (use (mem/f:SI (plus:SI (reg/f:SI 7 sp)
                        (const_int 4 [0x4])) [0  S4 A32]))
            (expr_list:SI (use (mem:SI (plus:SI (reg/f:SI 7 sp)
                            (const_int 8 [0x8])) [0  S4 A32]))
                (nil)))))

Please note that (insn 13) passes this address as source address to memcpy, so the initialization in (insn 8) and (insn 9) should not be removed. Please also note that removed two insns write to the same address, the first in BLKmode, and the second in SImode.

Looks like RTL-optimization problem to me. Adding CC.
Comment 2 Uroš Bizjak 2018-07-18 09:09:59 UTC
The issue here is that g escapes as an argument to memcpy, but this is not reported form local_variable_can_escape:

Breakpoint 1, local_variable_can_escape (decl=0x7fffe9ba3240) at ../../git/gcc/gcc/dse.c:910
910       if (TREE_ADDRESSABLE (decl))
Missing separate debuginfos, use: dnf debuginfo-install gmp-6.1.2-7.fc28.x86_64 isl-0.16.1-6.fc28.x86_64 libgcc-8.1.1-1.fc28.x86_64 libmpc-1.0.2-9.fc28.x86_64 libstdc++-8.1.1-1.fc28.x86_64 mpfr-3.1.6-1.fc28.x86_64
(gdb) p debug_generic_expr (decl)
g
$1 = void
(gdb) fin
Run till exit from #0  local_variable_can_escape (decl=0x7fffe9ba3240) at ../../git/gcc/gcc/dse.c:910
0x00000000013fb758 in can_escape (expr=0x7fffe9ba3240) at ../../git/gcc/gcc/dse.c:942
942                && local_variable_can_escape (base)))
Value returned is $2 = false

DSE just removes all stores to g as dead.

CC Honza.
Comment 3 Uroš Bizjak 2019-01-21 12:30:59 UTC
Dup of PR88906.

*** This bug has been marked as a duplicate of bug 88906 ***
Comment 4 Jakub Jelinek 2019-01-22 09:10:59 UTC
Author: jakub
Date: Tue Jan 22 09:10:25 2019
New Revision: 268138

URL: https://gcc.gnu.org/viewcvs?rev=268138&root=gcc&view=rev
Log:
	PR rtl-optimization/49429
	PR target/49454
	PR rtl-optimization/86334
	PR target/88906
	* expr.c (emit_block_move_hints): Move marking of MEM_EXPRs
	addressable from here...
	(emit_block_op_via_libcall): ... to here.

	* gcc.target/i386/pr86334.c: New test.
	* gcc.target/i386/pr88906.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr86334.c
    trunk/gcc/testsuite/gcc.target/i386/pr88906.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2019-02-07 14:36:02 UTC
Author: jakub
Date: Thu Feb  7 14:35:30 2019
New Revision: 268626

URL: https://gcc.gnu.org/viewcvs?rev=268626&root=gcc&view=rev
Log:
	Backported from mainline
	2019-01-22  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/49429
	PR target/49454
	PR rtl-optimization/86334
	PR target/88906
	* expr.c (emit_block_move_hints): Move marking of MEM_EXPRs
	addressable from here...
	(emit_block_op_via_libcall): ... to here.

	* gcc.target/i386/pr86334.c: New test.
	* gcc.target/i386/pr88906.c: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/gcc.target/i386/pr86334.c
    branches/gcc-8-branch/gcc/testsuite/gcc.target/i386/pr88906.c
Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/expr.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2019-08-30 11:30:28 UTC
Author: jakub
Date: Fri Aug 30 11:29:57 2019
New Revision: 275090

URL: https://gcc.gnu.org/viewcvs?rev=275090&root=gcc&view=rev
Log:
	Backported from mainline
	2019-01-22  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/49429
	PR target/49454
	PR rtl-optimization/86334
	PR target/88906
	* expr.c (emit_block_move_hints): Move marking of MEM_EXPRs
	addressable from here...
	(emit_block_op_via_libcall): ... to here.

	* gcc.target/i386/pr86334.c: New test.
	* gcc.target/i386/pr88906.c: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/gcc.target/i386/pr86334.c
    branches/gcc-7-branch/gcc/testsuite/gcc.target/i386/pr88906.c
Modified:
    branches/gcc-7-branch/gcc/ChangeLog
    branches/gcc-7-branch/gcc/expr.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog