public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "erosenberger at kinetica dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108243] New: Missed optimization for static const std::string_view(const char*) Date: Wed, 28 Dec 2022 16:31:55 +0000 [thread overview] Message-ID: <bug-108243-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108243 Bug ID: 108243 Summary: Missed optimization for static const std::string_view(const char*) Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: erosenberger at kinetica dot com Target Milestone: --- Given the following code: #include <string_view> int main() { static const std::string_view foo("bar"); return foo.size(); } With gcc 7.3.1, using "g++ -std=c++17 -O2", it treats foo as constexpr, and compiles main to: mov $0x3,%eax retq With gcc 11.3.0, also using "g++ -std=c++17 -O2", it does not treat foo as constexpr, using runtime initialization instead (with static guard, etc.) However, by using the string_view constructor that accepts a length: static const std::string_view foo("bar", 3); gcc 11.3.0 is then able to treat foo as constexpr and compiles to just a mov and ret as 7.3.1 does. Using Compiler Explorer it appears that gcc 9 is the first version where it lost the optimization; every subsequent version seems to behave as 11.3.0. --- Additional info: gcc 11.3.0: Using built-in specs. COLLECT_GCC=/usr/bin/g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --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-bootstrap --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-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) gcc 7.3.1: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)
next reply other threads:[~2022-12-28 16:31 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-28 16:31 erosenberger at kinetica dot com [this message] 2023-01-04 11:42 ` [Bug c++/108243] " redi at gcc dot gnu.org 2023-01-04 13:05 ` redi at gcc dot gnu.org 2023-01-04 13:15 ` redi at gcc dot gnu.org 2023-01-04 13:20 ` [Bug c++/108243] [10/11/12/13 Regression] " redi at gcc dot gnu.org 2023-01-04 13:21 ` redi at gcc dot gnu.org 2023-01-04 16:47 ` ppalka at gcc dot gnu.org 2023-01-04 17:22 ` jakub at gcc dot gnu.org 2023-01-09 14:05 ` rguenth at gcc dot gnu.org 2023-01-27 19:13 ` ppalka at gcc dot gnu.org 2023-02-17 20:21 ` cvs-commit at gcc dot gnu.org 2023-02-20 5:23 ` de34 at live dot cn 2023-02-20 18:33 ` ppalka at gcc dot gnu.org 2023-02-21 13:38 ` rguenth at gcc dot gnu.org 2023-02-21 14:09 ` ppalka at gcc dot gnu.org 2023-03-02 19:05 ` cvs-commit at gcc dot gnu.org 2023-03-02 19:05 ` cvs-commit at gcc dot gnu.org 2023-03-02 19:51 ` [Bug c++/108243] [10/11/12 " ppalka at gcc dot gnu.org 2023-07-07 10:44 ` [Bug c++/108243] [11/12 " rguenth at gcc dot gnu.org 2023-12-13 16:48 ` cvs-commit at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108243-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).