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

            Bug ID: 118153
           Summary: Wrong code generated due to selective scheduler on
                    RISC-V target
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luiss at synopsys dot com
  Target Milestone: ---

Created attachment 59936
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59936&action=edit
Test case

In the attached test case, there is incorrect code generation with a specific
set of options. It seems that the main issue is related to the selective
scheduler. The late-combine pass must be disabled to trigger the issue.

Execution command:
```
$ /home/luis/inst/bin/riscv64-unknown-elf-gcc \
    -fharden-control-flow-redundancy -fselective-scheduling \
    -fno-late-combine-instructions \
    -mabi=ilp32 -march=rv32i_zicsr -mcmodel=medany \
    -O3 test.i
$ /home/luis/inst/bin/qemu-riscv32 -r 5.10 a.out
checksum = 965B2E87
```

The expected output is `checksum = 18D42964`. Any modifications to the source
code or optimization options that affect the code flow, such as using -O2, will
trigger the expected result.


I'm using a GCC cross-compiler for RISC-V Baremetal Multilib (running on x64
Linux) - gcc version 12.2.0
GCC Trunk was used in this experiment. The output of "riscv64-unknown-elf-gcc
-v" is:
-------------
Using built-in specs.
COLLECT_GCC=/home/luis/inst/bin/riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/home/luis/inst/libexec/gcc/riscv64-unknown-elf/15.0.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /home/luis/src/gcc-trunk/configure
--target=riscv64-unknown-elf --prefix=/home/luis/inst --disable-shared
--disable-threads --enable-languages=c,c++ --with-pkgversion=g2d8982c27
--with-system-zlib --enable-tls --with-newlib
--with-sysroot=/home/luis/inst/riscv64-unknown-elf
--with-native-system-header-dir=/include --disable-libmudflap --disable-libssp
--disable-libquadmath --disable-libgomp --disable-nls
--disable-tm-clone-registry --src=/home/luis/src/gcc-trunk --enable-multilib
--with-abi=lp64d --with-arch=rv64gc --with-tune=rocket --with-isa-spec=20191213
'CFLAGS_FOR_TARGET=-Os    -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os   
-mcmodel=medlow'
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.0 20241220 (experimental) (g2d8982c27)
-------------

Reply via email to