Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pb when building with gcc-12 -Og #720

Closed
wants to merge 1 commit into from
Closed

Conversation

Mingli-Yu
Copy link

Fixes:
| xxhash.h:3932:1: error: inlining failed in call to 'always_inline' 'XXH3_accumulate_512_sse2': function not considered for inlining
| 3932 | XXH3_accumulate_512_sse2( void* XXH_RESTRICT acc,
| | ^~~~~~~~~~~~~~~~~~~~~~~~
| xxhash.h:4369:9: note: called from here
| 4369 | f_acc512(acc,
| | ^~~~~~~~~~~~~
| 4370 | in,
| | ~~~
| 4371 | secret + n*XXH_SECRET_CONSUME_RATE);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Mingli Yu mingli.yu@windriver.com

Fixes:
 | xxhash.h:3932:1: error: inlining failed in call to 'always_inline' 'XXH3_accumulate_512_sse2': function not considered for inlining
 |  3932 | XXH3_accumulate_512_sse2( void* XXH_RESTRICT acc,
 |       | ^~~~~~~~~~~~~~~~~~~~~~~~
 | xxhash.h:4369:9: note: called from here
 |  4369 |         f_acc512(acc,
 |       |         ^~~~~~~~~~~~~
 |  4370 |                  in,
 |       |                  ~~~
 |  4371 |                  secret + n*XXH_SECRET_CONSUME_RATE);
 |       |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
@t-mat
Copy link
Contributor

t-mat commented Jun 10, 2022

Hi @Mingli-Yu,
thank you for sending PR. But unfortunately your PR has failed to pass our test. Also I couldn't repro your issue with gcc-12.1.

First of all, please understand that we can't accept your PR for now. Because your PR failed to pass our test. But I also must say that our test is not perfect. So feel free to point out our mistake.


I failed to reproduce your issue with gcc-12.1

I've tried to build xxhsum and make test with gcc-12.1 by the following commands which found at reddit.

cd

# spack is the cleanest package manager BTW.
git clone -c feature.manyFiles=true https://github.com/spack/spack.git
. spack/share/spack/setup-env.sh
spack install gcc@12.1
spack load gcc@12.1
gcc --version
# gcc (Spack GCC) 12.1.0

git clone --depth 1 https://github.com/Cyan4973/xxHash.git
cd xxHash

make
make test
CPPFLAGS="-mavx2 -DXXH_VECTOR=XXH_AVX2" make clean check
# build xxhsum and pass all tests

./xxhsum --version
# xxhsum 0.8.1 by Yann Collet
# compiled as 64-bit x86_64 + AVX2 little endian with GCC 12.1.0

During the build and test process, I don't see any warning and error. Since you've posted specific error message, I think I missed something. But honestly, I have no idea.


I don't understand intention of your PR.

(1) Same question again, but I don't see any warning (as an error) from these __inline__ and __attribue__((always_inline)) in the macro. How can we reproduce your issue?

(2) Why you removed __attribute__((unused))? According to the gcc manual, I think this attribute may help to ease/resolve yor situation. At least it may help our test.

unused
This attribute, attached to a function, means that the function is meant to be possibly unused. GCC does not produce a warning for this function.

@jrosdahl
Copy link

Looks like @Mingli-Yu forgot to mention that the issue only shows up when using -Og.

@t-mat
Copy link
Contributor

t-mat commented Jul 19, 2022

Hi @jrosdahl, thanks for the info!
Now I can reproduce this issue with the following command:

CFLAGS="-Og" CC="gcc-12" make clean default  # NG

Since I have no idea so far, I just put some random commands for further investigation.

# gcc-12 -Og
CFLAGS="-Og -no-mavx2"   CC="gcc-12" make clean default  # NG (SSE2)
CFLAGS="-Og -msse2"      CC="gcc-12" make clean default  # NG (SSE2)
CFLAGS="-Og -mavx2"      CC="gcc-12" make clean default  # OK (AVX2)
CFLAGS="-Og -mhaswell"   CC="gcc-12" make clean default  # OK (AVX2)

# gcc-12 -O?
CFLAGS="-O0"             CC="gcc-12" make clean default  # OK (SSE2)
CFLAGS="-O1"             CC="gcc-12" make clean default  # OK (SSE2)
CFLAGS="-O1 -fno-inline" CC="gcc-12" make clean default  # OK (SSE2)

# gcc-11 -Og
CFLAGS="-Og"             CC="gcc-11" make clean default  # OK (SSE2)

@tristan957
Copy link

Just to add another data point, I can also confirm this. I have been investigating a little bit on my end.

tristan957 added a commit to tristan957/wrapdb that referenced this pull request Aug 23, 2022
tristan957 added a commit to tristan957/wrapdb that referenced this pull request Aug 23, 2022
@tristan957
Copy link

tristan957 commented Aug 24, 2022

I have fixed the meson build in mesonbuild/wrapdb#580, specifically mesonbuild/wrapdb@e9b59a6.

I think this PR has to do something similar, but I am not going to touch it because I have no clue how to tell what optimization level the compiler is using in Makefiles. I haven't found a pure C preprocessor solution. I would seriously just recommend using Meson for xxhash though :).

tristan957 added a commit to tristan957/wrapdb that referenced this pull request Aug 24, 2022
tristan957 added a commit to tristan957/wrapdb that referenced this pull request Aug 24, 2022
eli-schwartz pushed a commit to mesonbuild/wrapdb that referenced this pull request Aug 24, 2022
kcgen pushed a commit to dosbox-staging/wrapdb that referenced this pull request Oct 27, 2022
@Cyan4973
Copy link
Owner

Cyan4973 commented Feb 2, 2023

Indeed, -Og seems to be "a compilation mode optimized for debugging".
Given the definition, I would expect this compilation mode to be rather hostile to inlining, since inlining can make debugging more difficult.

Somehow, -Og feels superficially similar to -O0 -g.

-O0 is detectable, by checking macro __NO_INLINE__ (cc @easyaspi314).
For some reason, -Og on gcc-12 doesn't expose the __NO_INLINE__ macro when selected.
If it's not going to respect the inline statements, it probably should.

At least, that's the situation with gcc-12. But clang on the other hand has no such problem.

I don't have access to older versions of gcc to check if the same pb happens.
Will try again later, when I can access another system with more compilers.

@Cyan4973 Cyan4973 changed the title xxhash.h: Fix build with gcc-12 Pb when building with gcc-12 -Og Feb 2, 2023
@easyaspi314
Copy link
Contributor

easyaspi314 commented Feb 3, 2023

Hmm, this is a tricky one. GCC 12 doesn't seem to emit any different macros on -Og vs -O2.

gcc-mirror/gcc@c952126 might be the culprit

The problem seems to be specifically -Og preventing GCC from inlining the accumulate functions because they are accessed through function pointers.

My guess is to either disable force inline on the accumulate functions themselves or force GCC into -O3 mode if neither -O0, -Os, or -fno-inline is used, similar to how GCC is forced to do in AVX2 (which by the way the load splitting bug seems to have been fixed, might need to find the commit to disable it on newer versions)

If we can get them to be inlined naturally (such as via static inline) this might work.

@eugeneko
Copy link

I have also encountered this issue. Any workarounds except removing -Og from our compiler options?

@tristan957
Copy link

Using the Meson build will fix this issue if that is possible for you.

@t-mat
Copy link
Contributor

t-mat commented May 30, 2023

Hi @eugeneko, please try the HEAD of dev branch
or apply the following patch

Since #814 added CI test for gcc-12 -Og, we're sure that HEAD of dev branch has no problem with gcc-12 -Og.

You can also try it in your terminal

gcc-12 --version
# gcc-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0

cd
git clone https://github.com/Cyan4973/xxHash.git
cd xxHash

git branch -v
# * dev 616ca44 minor comment update

CFLAGS="-Og" CC="gcc-12" make clean default

./xxhsum --version
# xxhsum 0.8.1 by Yann Collet compiled as 64-bit x86_64 + SSE2 little endian with GCC 12.1.0

@Cyan4973
Copy link
Owner

Fixed in #804

@Cyan4973 Cyan4973 closed this Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants