commit:     83a27ac5162cf15e1dca6de92f2debe452024d24
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 16 01:21:09 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Apr 16 01:24:25 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=83a27ac5

app-arch/xz-utils: improve USE=pgo for 9999

Takes a lot of inspiration from 
https://packages.altlinux.org/en/sisyphus/srpms/xz/specfiles/#line-80.

IIRC at least one other distro does this for xz or gzip (was it Clear Linux?)

The testsuite could do with better coverage so supplement it by creating
a tar archive of a bunch of files made during the build, then repeatedly
compress/decompress it to gather profiling data.

That said, I don't get any binary differences at all for liblzma and xz
for my usual flags (-O3 -march=znver2 ...). I do get some small differences
for just -O2. Both tests were done with GCC 14.0.1 20240415.

It would be nice if we could drop -fprofile-partial-training and that's
perhaps the thing to try next. I see this commit as mostly a step towards
being able to do that which should let PGO give smaller binaries with -O2
at least.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 app-arch/xz-utils/xz-utils-9999.ebuild | 38 ++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/app-arch/xz-utils/xz-utils-9999.ebuild 
b/app-arch/xz-utils/xz-utils-9999.ebuild
index ec5227371390..d2e98e50e15a 100644
--- a/app-arch/xz-utils/xz-utils-9999.ebuild
+++ b/app-arch/xz-utils/xz-utils-9999.ebuild
@@ -106,6 +106,7 @@ multilib_src_configure() {
 
 multilib_src_compile() {
        # -fprofile-partial-training because upstream note the test suite isn't 
super comprehensive
+       # TODO: revisit that now we have the tar/xz loop below?
        # See 
https://documentation.suse.com/sbp/all/html/SBP-GCC-10/index.html#sec-gcc10-pgo
        local pgo_generate_flags=$(usev pgo "-fprofile-update=atomic 
-fprofile-dir=${T}/${ABI}-pgo -fprofile-generate=${T}/${ABI}-pgo 
$(test-flags-CC -fprofile-partial-training)")
        local pgo_use_flags=$(usev pgo "-fprofile-use=${T}/${ABI}-pgo 
-fprofile-dir=${T}/${ABI}-pgo $(test-flags-CC -fprofile-partial-training)")
@@ -115,6 +116,43 @@ multilib_src_compile() {
        if use pgo ; then
                emake CFLAGS="${CFLAGS} ${pgo_generate_flags}" -k check
 
+               if multilib_is_native_abi ; then
+                       (
+                               shopt -s globstar
+
+                               tar \
+                                       --sort=name --mtime=@2718281828 \
+                                       -cf xz-pgo-test-01.tar \
+                                       {"${S}","${BUILD_DIR}"}/**/*.[cho] \
+                                       {"${S}","${BUILD_DIR}"}/**/*.so* \
+                                       {"${S}","${BUILD_DIR}"}/**/**.txt \
+                                       {"${S}","${BUILD_DIR}"}/tests/files \
+
+                               stat --printf="xz-pgo-test-01.tar.tar size: 
%s\n" xz-pgo-test-01.tar
+                               md5sum xz-pgo-test-01.tar
+                       )
+
+                       local test_variants=(
+                               # Borrowed from ALT Linux
+                               # 
https://packages.altlinux.org/en/sisyphus/srpms/xz/specfiles/#line-80
+                               '-0 -C none'
+                               '-2 -C crc32'
+                               '-6 --arm --lzma2 -C crc64'
+                               '-6 --x86 --lzma2=lc=4 -C sha256'
+                               '-7e --format=lzma'
+
+                               # Our own variants
+                               ''
+                               '-9e'
+                               '--x86 --lzma2=preset=9e'
+                       )
+                       local test_variant
+                       for test_variant in "${test_variants[@]}" ; do
+                               "${BUILD_DIR}"/src/xz/xz -c ${test_variant} 
xz-pgo-test-01.tar | "${BUILD_DIR}"/src/xz/xz -c -d - > /dev/null
+                               assert "Testing '${test_variant}' variant 
failed"
+                       done
+               fi
+
                if tc-is-clang; then
                        llvm-profdata merge "${T}"/${ABI}-pgo 
--output="${T}"/${ABI}-pgo/default.profdata || die
                fi

Reply via email to