Bug 116878 - [15 regression] libcall emitted unnecessarily for __popcountdi2
Summary: [15 regression] libcall emitted unnecessarily for __popcountdi2
Status: RESOLVED DUPLICATE of bug 116616
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: 15.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2024-09-28 19:30 UTC by Sam James
Modified: 2024-10-03 02:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2024-09-28 19:30:39 UTC
Hit this with an `allmodconfig` of linux-6.6.52 (aware of the controversy there in general).

When building the following w/ `-O2 -fsanitize-coverage=trace-cmp`, it looks lik we get an inefficient(?) libcall to _popcountdi2:
```
int s_jquota_fmt;
void seq_printf();
void ext4_init_fs_contextext4_show_options() {
  char *fmtname = "";
  switch (s_jquota_fmt) {
  case 1:
    fmtname = "vfsold";
    break;
  case 2:
    fmtname = "vfsv0";
    break;
  case 4:
    fmtname = "vfsv1";
  }
  seq_printf(fmtname);
}
```

See https://godbolt.org/z/TjTMW345h. With 14, we don't emit the libcall, and Clang doesn't either (but needs -fno-jump-tables as well as the kernel originally built with).

--

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/15/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-15.0.9999/work/gcc-15.0.9999/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/15 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/15/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15 --disable-silent-rules --disable-dependency-tracking --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/15/python --enable-objc-gc --enable-languages=c,c++,d,go,objc,obj-c++,fortran,ada,m2,rust --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=yes,extra,rtl --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo Hardened 15.0.9999 p, commit 3e1c7a2699f90793d9bf7107cb0b5943ba7c76c1' --with-gcc-major-version-only --enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --enable-libada --disable-cet --disable-systemtap --enable-valgrind-annotations --disable-vtable-verify --disable-libvtv --with-zstd --with-isl --disable-isl-version-check --enable-default-pie --enable-host-pie --enable-host-bind-now --enable-default-ssp --disable-fixincludes --with-build-config='bootstrap-O3 bootstrap-lto'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.0 20240927 (experimental) 0ff49a5c1d39382c57d614a29510559068947376 (Gentoo Hardened 15.0.9999 p, commit 3e1c7a2699f90793d9bf7107cb0b5943ba7c76c1)
Comment 2 Filip Kastl 2024-10-02 12:31:12 UTC
Yeah, sorry about that.  I just pushed the patch that Andrew linked.  That should fix this.  I'll close this PR if no one objects.
Comment 3 Sam James 2024-10-03 02:29:48 UTC
All good - thanks!

*** This bug has been marked as a duplicate of bug 116616 ***