public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104763] New: [12.0] Generate wrong assembly code
@ 2022-03-02 18:01 570070308 at qq dot com
  2022-03-02 18:44 ` [Bug c/104763] " 570070308 at qq dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: 570070308 at qq dot com @ 2022-03-02 18:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104763
           Summary: [12.0] Generate wrong assembly code
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 570070308 at qq dot com
  Target Milestone: ---

file test.c:
```
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
void move_up()
{
    for ( size_t* i=(size_t *)(0xb8000+160*24); ; )
    {
        *i=0x0700070007000700;
        //if ( i == (size_t *)(0xb8000+160*24+7*sizeof(size_t)) )
        if ( i == (volatile size_t *)(0xb8000+160*24)+2 )
        {
            break;
        }
        ++i;
    }
    while (1){}
}
```
compile with `gcc -O1 test.c -S` or -O2 or -O3
the assemble code:
```
move_up:
.LFB0:
    .cfi_startproc
    endbr64
    movabsq $504410854964332288, %rax
    movq    %rax, 757512
    movq    %rax, 757520
.L2:
    jmp .L2
    .cfi_endproc
```

But the correct assembly code should be:
```
move_up:
    movabsq $504410854964332288, %rax
    movq    %rax, 757504
    movq    %rax, 757512
    movq    %rax, 757520
.L2:
    jmp .L2
```

I try to compile with -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -Wall -Wextra and the result is same.

This is the full gcc compile info:
```
ig@ig-virtual-machine:~/os/myos/temp$ gcc -O1 test.c -S -v
Using built-in specs.
COLLECT_GCC=gcc
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
12-20220222-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-12-TT8eTw/gcc-12-12-20220222/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-TT8eTw/gcc-12-12-20220222/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.1 20220222 (experimental) [master r12-7325-g2f59f067610]
(Ubuntu 12-20220222-1ubuntu1) 
COLLECT_GCC_OPTIONS='-O1' '-S' '-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu
test.c -quiet -dumpbase test.c -dumpbase-ext .c -mtune=generic -march=x86-64
-O1 -version -o test.s -fasynchronous-unwind-tables -fstack-protector-strong
-Wformat -Wformat-security -fstack-clash-protection -fcf-protection
GNU C17 (Ubuntu 12-20220222-1ubuntu1) version 12.0.1 20220222 (experimental)
[master r12-7325-g2f59f067610] (x86_64-linux-gnu)
        compiled by GNU C version 12.0.1 20220222 (experimental) [master
r12-7325-g2f59f067610], GMP version 6.2.1, MPFR version 4.1.0, MPC version
1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/12/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C17 (Ubuntu 12-20220222-1ubuntu1) version 12.0.1 20220222 (experimental)
[master r12-7325-g2f59f067610] (x86_64-linux-gnu)
        compiled by GNU C version 12.0.1 20220222 (experimental) [master
r12-7325-g2f59f067610], GMP version 6.2.1, MPFR version 4.1.0, MPC version
1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b0de683ccdd6a31c725d9273cea9e1f8
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-O1' '-S' '-v' '-mtune=generic' '-march=x86-64'
```
The gcc is installed by apt on ubuntu 22.04.

If I change the `while (1){}` to `return ;` then the code will be right.

Or change the `+2` of `(volatile size_t *)(0xb8000+160*24)+2` to `+1` or `+0`.

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

end of thread, other threads:[~2022-03-07  9:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02 18:01 [Bug c/104763] New: [12.0] Generate wrong assembly code 570070308 at qq dot com
2022-03-02 18:44 ` [Bug c/104763] " 570070308 at qq dot com
2022-03-02 18:58 ` jakub at gcc dot gnu.org
2022-03-03  5:08 ` [Bug middle-end/104763] " 570070308 at qq dot com
2022-03-03 11:35 ` [Bug middle-end/104763] [12 Regression] " marxin at gcc dot gnu.org
2022-03-07  8:03 ` rguenth at gcc dot gnu.org
2022-03-07  8:07 ` rguenth at gcc dot gnu.org
2022-03-07  8:12 ` rguenth at gcc dot gnu.org
2022-03-07  8:37 ` 570070308 at qq dot com
2022-03-07  9:05 ` rguenth 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).