GCC-12 fails to inline XXX_FORCED_INLINE functions, XXH3_accumulate_512_sse2(), and XXH3_scrambleAcc_sse2() with -Og flag. #800

Closed
opened 2023-02-18 17:54:37 -06:00 by zephyrus00jp · 7 comments
zephyrus00jp commented 2023-02-18 17:54:37 -06:00 (Migrated from github.com)

Hi, I tried compiling Thunderbird mail client using GCC-12.
Well, with -Og flag, it fails to inline the following two functions and compilation aborts.

XXH3_accumulate_512_sse2()
XXH3_scrambleAcc_sse2()

Without -Og, the compilation succeeds.
Mozilla bugzilla is here.
https://bugzilla.mozilla.org/show_bug.cgi?id=1817565

I was advised to post a bug report at this github repository.

I think we may need to enable/disable XXX_FORCED_INLINE attribute for these two functions depending on the GCC version and
whether -Og is used. But according to gcc bugzilla, there is currently no such macro that is defined when -Og is used on the command line.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107931

Come to think of it, macro is a preprocessor feature and so whether -Og is used or not is no concern to the preprocessor.
So it figures.

I need to settle on a certain macro such as __GCC_12_FAILS_ALWAYS_INLINE_WITH_DEBUG_OPT
and wrap the XXX_FORCED_INLINE attribute for the two functions as follows.
#if ! defined(__GCC_12_FAILS_ALWAYS_INLINE_WITH_DEBUG_OPT)
XXX_FORCED_INLINE
#endif

And then when I use -Og, I will define -D__GCC_12FAILS_ALWAYS_INLINE_WITH_DEBUG_OPT
and unless this macro is defined, all is well. The functions would be inlined. (At least GCC will not complain.)

It seems to be a compiler-specific and version-specific problem (GCC-10, GCC-11 did not report the errors. B now I am not quite convinced whether they really inlined the functions or not. According the gcc bugzilla, sometimes errors were/are not reported.)
So there is not much we can do. I just wanted to let you know the issue exists.

BUT if some measures are taken here, I don't have to modify my local Mozilla source code which imports xxhash source tree, and everybody who would compile xxHash with gcc-12 and -Og will be happier about it. :-)

Thank you for making a very fast hash library available to the general programming community.

Hi, I tried compiling Thunderbird mail client using GCC-12. Well, with -Og flag, it fails to inline the following two functions and compilation aborts. XXH3_accumulate_512_sse2() XXH3_scrambleAcc_sse2() Without -Og, the compilation succeeds. Mozilla bugzilla is here. https://bugzilla.mozilla.org/show_bug.cgi?id=1817565 I was advised to post a bug report at this github repository. I think we may need to enable/disable XXX_FORCED_INLINE attribute for these two functions depending on the GCC version and whether -Og is used. But according to gcc bugzilla, there is currently no such macro that is defined when -Og is used on the command line. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107931 Come to think of it, macro is a preprocessor feature and so whether -Og is used or not is no concern to the preprocessor. So it figures. I need to settle on a certain macro such as __GCC_12_FAILS_ALWAYS_INLINE_WITH_DEBUG_OPT and wrap the XXX_FORCED_INLINE attribute for the two functions as follows. #if ! defined(__GCC_12_FAILS_ALWAYS_INLINE_WITH_DEBUG_OPT) XXX_FORCED_INLINE #endif And then when I use -Og, I will define -D__GCC_12FAILS_ALWAYS_INLINE_WITH_DEBUG_OPT and unless this macro is defined, all is well. The functions would be inlined. (At least GCC will not complain.) It seems to be a compiler-specific and version-specific problem (GCC-10, GCC-11 did not report the errors. B now I am not quite convinced whether they really inlined the functions or not. According the gcc bugzilla, sometimes errors were/are not reported.) So there is not much we can do. I just wanted to let you know the issue exists. BUT if some measures are taken here, I don't have to modify my local Mozilla source code which imports xxhash source tree, and everybody who would compile xxHash with gcc-12 and -Og will be happier about it. :-) Thank you for making a very fast hash library available to the general programming community.
Cyan4973 commented 2023-02-18 18:12:17 -06:00 (Migrated from github.com)

Indeed, there are known issues when compiling libxxhash with the -Og flag on modern gcc version : https://github.com/Cyan4973/xxHash/pull/720

Unfortunately, there is no "generic" solution yet,
partially because -Og doesn't provide any indication that it is being employed to the preprocessor, so it can't adjust the source code.

It's unclear if there will be a solution to this problem, or if it's something that can only be fixed on the compiler side.

A manual work around involves combining this flag with an appropriate xxhash build macro, such as XXH_NO_INLINE_HINTS, though it obviously impacts performance.

Indeed, there are known issues when compiling `libxxhash` with the `-Og` flag on modern `gcc` version : https://github.com/Cyan4973/xxHash/pull/720 Unfortunately, there is no "generic" solution yet, partially because `-Og` doesn't provide any indication that it is being employed to the preprocessor, so it can't adjust the source code. It's unclear if there will be a solution to this problem, or if it's something that can only be fixed on the compiler side. A manual work around involves combining this flag with an appropriate xxhash build macro, such as `XXH_NO_INLINE_HINTS`, though it obviously impacts performance.
easyaspi314 commented 2023-02-18 18:29:50 -06:00 (Migrated from github.com)

I believe the solution is to not mark the functions that are turned into pointers force inline, as -Og tries to guarantee that pointers are not optimized out.

I believe the solution is to not mark the functions that are turned into pointers force inline, as `-Og` tries to guarantee that pointers are not optimized out.
Cyan4973 commented 2023-02-18 18:35:33 -06:00 (Migrated from github.com)

I believe the solution is to not mark the functions that are turned into pointers force inline, as -Og tries to guarantee that pointers are not optimized out.

Well, this is what XXH_NO_INLINE_HINTS achieves.
So there is a work around.
I presume the issue is that this build macro is not automatically triggered when compiling with -Og.
And it's unclear if this can be done, since -Og doesn't expose any standard macro for detection.

> I believe the solution is to not mark the functions that are turned into pointers force inline, as `-Og` tries to guarantee that pointers are not optimized out. Well, this is what `XXH_NO_INLINE_HINTS` achieves. So there is a work around. I presume the issue is that this build macro is not automatically triggered when compiling with `-Og`. And it's unclear if this can be done, since `-Og` doesn't expose any standard macro for detection.
zephyrus00jp commented 2023-02-21 01:18:36 -06:00 (Migrated from github.com)

I think I will define

__NO_INLINE__

manually when I compile thunderbird mail client with GCC-12 and -Og flag.
That seems to take care of the issue.
Indeed, I could compile the code with -Og using gcc-12 after -D__NO_INLINE__ is added.

https://github.com/Cyan4973/xxHash/pull/720#issuecomment-1414481935

I think I will define `__NO_INLINE__ ` manually when I compile thunderbird mail client with GCC-12 and -Og flag. That seems to take care of the issue. Indeed, I could compile the code with -Og using gcc-12 after -D__NO_INLINE__ is added. https://github.com/Cyan4973/xxHash/pull/720#issuecomment-1414481935
easyaspi314 commented 2023-02-21 14:01:11 -06:00 (Migrated from github.com)

I think I will define

__NO_INLINE__

manually when I compile thunderbird mail client with GCC-12 and -Og flag.
That seems to take care of the issue.
Indeed, I could compile the code with -Og using gcc-12 after -D__NO_INLINE__ is added.

https://github.com/Cyan4973/xxHash/pull/720#issuecomment-1414481935

-DXXH_NO_INLINE_HINTS=1 functionally does the same thing without modifying reserved macros. xxHash selects these things when these macros are defined but they all can be defined manually.

> I think I will define > > `__NO_INLINE__ ` > > manually when I compile thunderbird mail client with GCC-12 and -Og flag. > That seems to take care of the issue. > Indeed, I could compile the code with -Og using gcc-12 after -D__NO_INLINE__ is added. > > https://github.com/Cyan4973/xxHash/pull/720#issuecomment-1414481935 > `-DXXH_NO_INLINE_HINTS=1` functionally does the same thing without modifying reserved macros. xxHash selects these things when these macros are defined but they all can be defined manually.
t-mat commented 2023-03-11 20:55:12 -06:00 (Migrated from github.com)

I think #804 fixes this issue. If you can merge it, please let us know what happens in your project.

I think #804 fixes this issue. If you can merge it, please let us know what happens in your project.
t-mat commented 2023-07-01 09:36:51 -05:00 (Migrated from github.com)

We can close this issue, since #802, #804 and #810 have resolved/ensured it. Ping @Cyan4973

We can close this issue, since #802, #804 and #810 have resolved/ensured it. Ping @Cyan4973
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Cyan4973/xxHash#800
No description provided.