public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/108595] New: -fcall-saved-a1 with -O2 leads to incorrect RISC-V code-gen around inline assembly
@ 2023-01-30  7:44 idan.horowitz at gmail dot com
  2023-01-30 11:54 ` [Bug target/108595] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: idan.horowitz at gmail dot com @ 2023-01-30  7:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108595
           Summary: -fcall-saved-a1 with -O2 leads to incorrect RISC-V
                    code-gen around inline assembly
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: idan.horowitz at gmail dot com
  Target Milestone: ---

Created attachment 54370
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54370&action=edit
preprocessed reproducer

The attached code snippet compiled with `-fcall-saved-a1` (which is usually a
caller-saved register) and `-O2` erroneously saves/restores `a1` around the
inline assembly, as if it's a function call. Since GCC allocates `a1` for the
use of the inline assembly, this means that the result of the inline assembly
is clobbered. Note that this issue does not happen with `-O0` or `-O1`, so it
sounds like an optimizer issue to me.

GCC information:
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/riscv64/gcc-12.2.0/riscv64-unknown-linux-gnu/bin/riscv64-unknown-linux-gnu-gcc
Target: riscv64-unknown-linux-gnu
Configured with: /opt/.build/riscv64-unknown-linux-gnu/src/gcc/configure
--build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu
--target=riscv64-unknown-linux-gnu
--prefix=/opt/compiler-explorer/riscv64/gcc-12.2.0/riscv64-unknown-linux-gnu
--exec_prefix=/opt/compiler-explorer/riscv64/gcc-12.2.0/riscv64-unknown-linux-gnu
--with-sysroot=/opt/compiler-explorer/riscv64/gcc-12.2.0/riscv64-unknown-linux-gnu/riscv64-unknown-linux-gnu/sysroot
--enable-languages=c,c++,fortran,ada,d,objc,obj-c++,go --with-arch=rv64gc
--with-abi=lp64d --with-pkgversion='crosstool-NG UNKNOWN' --enable-__cxa_atexit
--enable-libmudflap --enable-libgomp --enable-libssp --enable-libquadmath
--enable-libquadmath-support --disable-libsanitizer --disable-libmpx
--with-gmp=/opt/.build/riscv64-unknown-linux-gnu/buildtools
--with-mpfr=/opt/.build/riscv64-unknown-linux-gnu/buildtools
--with-mpc=/opt/.build/riscv64-unknown-linux-gnu/buildtools
--with-isl=/opt/.build/riscv64-unknown-linux-gnu/buildtools --enable-lto
--enable-threads=posix --enable-target-optspace --disable-plugin --disable-nls
--disable-multilib
--with-local-prefix=/opt/compiler-explorer/riscv64/gcc-12.2.0/riscv64-unknown-linux-gnu/riscv64-unknown-linux-gnu/sysroot
--enable-long-long
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (crosstool-NG UNKNOWN) 

The code itself is very short, but the `stdint.h` and `stddef.h` headers make
the preprocessed file pretty large, so it's attached.

Godbolt link which encompasses all of the above:
https://godbolt.org/z/h7rnGcqGh

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

end of thread, other threads:[~2023-01-30 17:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30  7:44 [Bug rtl-optimization/108595] New: -fcall-saved-a1 with -O2 leads to incorrect RISC-V code-gen around inline assembly idan.horowitz at gmail dot com
2023-01-30 11:54 ` [Bug target/108595] " pinskia at gcc dot gnu.org
2023-01-30 11:56 ` pinskia at gcc dot gnu.org
2023-01-30 12:05 ` idan.horowitz at gmail dot com
2023-01-30 17:41 ` pinskia 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).