From: Joe Perches <joe@perches.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Colin Ian King <colin.king@canonical.com>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Sven Schmidt <4sschmid@informatik.uni-hamburg.de>,
Andrew Morton <akpm@linux-foundation.org>,
kernel-janitors@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] lib/lz4: make arrays static const, reduces object code size
Date: Sat, 23 Sep 2017 01:33:46 +0000 [thread overview]
Message-ID: <1506130426.12311.51.camel@perches.com> (raw)
In-Reply-To: <CAK8P3a3KLjuntMkJW3xkgO5a-nTBVZm8LJVnX-RwsWJ084kuOw@mail.gmail.com>
On Fri, 2017-09-22 at 21:17 +0200, Arnd Bergmann wrote:
> On Fri, Sep 22, 2017 at 7:21 PM, Joe Perches <joe@perches.com> wrote:
> > On Fri, 2017-09-22 at 09:48 +0200, Arnd Bergmann wrote:
> > > On Fri, Sep 22, 2017 at 1:11 AM, Colin Ian King
> > > text data bss dec hex filename
> > > 18220 176 0 18396 47dc build/tmp/lib/lz4/lz4_decompress-after.o
> > > 22297 0 0 22297 5719 build/tmp/lib/lz4/lz4_decompress-before.o
> >
> > Perhaps not so much a gcc bug as an opportunity
> > for gcc to add an additional optimization.
> >
> > gcc would have to verify that the const array is
> > not initialized with some variable or argument like:
> >
> > int foo(int a)
> > {
> > const int array[] = {1, a};
> > ...
> > }
>
> It depends. With a 10KB different in .text size, my guess is that this
> is a case where gcc does the right optimization in principle, but
> fails to do what was intended in some corner cases.
Maybe/maybe not.
> I just cross-checked by building with clang, there the patch has
> no impact on code size, it is 24929 bytes with or without the patch.
>
> Looking at other versions of (x86) gcc, I see .text sizes of
>
> after before
> gcc-3.4.6 10855 12977
> gcc-4.0.4 11088 11088
> gcc-4.1.3 10973 10973
> gcc-4.2.5 11183 11183
> gcc-4.3.6 15501 17724
Interesting this was apparently deoptimized at version 4.3.
Glancing at the release notes doesn't seem to indicate
anything obvious.
https://gcc.gnu.org/gcc-4.3/changes.html
> gcc-4.4.7 13337 15693
> gcc-4.5.4 13162 15491
> gcc-4.6.4 14846 17302
> gcc-4.7.4 14187 16294
> gcc-4.8.5 16591 18730
> gcc-4.9.4 19582 21995
> gcc-5.4.1 18294 22510
> gcc-6.1.1 20487 25172
> gcc-6.3.1 20487 25172
> gcc-7.0.0 20351 31789
> gcc-7.0.1 20351 24966
> gcc-7.1.1 20383 24982
> gcc-8.0.0 20686 25065
>
> It seems whatever happened in early versions of gcc-7 has since
> improved, and it probably was a bug since older and newer versions
> create similar code size (I have not looked at the actual object code).
>
> The 5K difference in gcc-5 and higher still seems like a lot. It would
> also be interesting to look at the decompression performance of
> this code witth the different compilers to see if it got better or worse.
yup
> Most likely, gcc got better at inlining and unrolling parts of the
> algorithm, but sometimes an object file that doubles or triples in
> size is an indication that the compiler did something really bad.
yup[2]
cheers, Joe
prev parent reply other threads:[~2017-09-23 1:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 22:19 [PATCH] lib/lz4: make arrays static const, reduces object code size Colin King
2017-09-21 23:09 ` Christophe JAILLET
2017-09-21 23:11 ` Colin Ian King
2017-09-22 7:48 ` Arnd Bergmann
2017-09-22 17:21 ` Joe Perches
2017-09-22 19:17 ` Arnd Bergmann
2017-09-22 19:38 ` Arnd Bergmann
2017-09-22 21:39 ` Arnd Bergmann
2017-09-22 21:43 ` Colin Ian King
2017-09-23 1:33 ` Joe Perches
2017-09-23 1:33 ` Joe Perches [this message]
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=1506130426.12311.51.camel@perches.com \
--to=joe@perches.com \
--cc=4sschmid@informatik.uni-hamburg.de \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=christophe.jaillet@wanadoo.fr \
--cc=colin.king@canonical.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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: link
Be 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