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

            Bug ID: 122035
           Summary: Wrong behavior under -O2 and -O3 optimization
           Product: gcc
           Version: 15.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: krzysiu858519851 at gmail dot com
  Target Milestone: ---

I was exploring 1BRC in C++, slowly progressing further, when I notices that
executable, compiled with g++ is around 80% slower than clang++, using the same
compiler flag. Then I noticed that something strange is happening for g++, when
doing `substr` on `std::string`. Further investigation result in discovery,
that this problem is reproducible with -O2 and -O3 flags for g++ (with no
flags, or -O1 it does work fine)

GCC version:
g++ (GCC) 15.2.1 20250813

OS:
Manjaro Linux x86_64
Kernel: Linux 6.17.0-rc4-1-MANJARO

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.2.1 20250813 (GCC) Options given when GCC was configured/built:

The complete command line that triggers the bug:
g++ -O1 -mavx2 -std=c++26 main.cpp -o main_gcc

The compiler output (error messages, warnings, etc.):
None

The preprocessed file (*.i*) that triggers the bug:
In attachment

Reply via email to