public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PIC calls without PLT, generic implementation
@ 2015-05-04 16:38 Alexander Monakov
  2015-05-04 16:38 ` [RFC PATCH] ira: accept loads via argp rtx in validate_equiv_mem Alexander Monakov
                   ` (5 more replies)
  0 siblings, 6 replies; 106+ messages in thread
From: Alexander Monakov @ 2015-05-04 16:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexander Monakov, Rich Felker, Sriraman Tallam

Recent post by Sriraman prompts me to post my -fno-plt approach sooner rather
than later; I was working on no-PLT PIC codegen in last few days too.
Although I'm posting a patch series, half of it is i386 backend tuning and can
go in independently.  Except one patch where it's noted specifically, the
patches were bootstrapped and regtested together, not separately, on x86-64.
Likewise the improvement claimed below is obtained with GCC with all patches
applied, the difference being only in -fno-plt flag.

The approach taken here is different.  Instead of adjusting call expansion in
the back end, I force callee address to be loaded into a pseudo at RTL
expansion time, similar to "function CSE" which is not enabled to most
targets.  The address load (which loads from GOT) can be moved out of loops,
scheduled, or, on x86, re-fused with indirect jump by peepholes.  On 32-bit
x86, it also allows the compiler to use registers other than %ebx for GOT
pointer (which can be a win since %ebx is callee-saved).

The benefit of PLT is the possibility of lazy relocation.  It is not possible
with BIND_NOW, in particular when -z relro -z now flags were used at link time
as security hardening measure.  Performance-critical executables do not
particularly need PLT and lazy relocation too, except if they are used very
frequently, with each individual run time extremely small -- but in that case
they can benefit massively from static linking or less massively from
prelinking, and with prelinking they can get the benefit of no-plt.

I've used LLVM/Clang to evaluate performance impact of PLT-less PIC codegen.
I configured with
  cmake -DLLVM_ENABLE_PIC=ON -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF
from 3.6 release branch; this configuration mimics non-static build that e.g.
OpenSUSE is using, and produces Clang dependent on 112 clang/llvm shared
libraries, with roughly 24000 externally visible functions.

Without input files time is mostly spent on dynamic linking, so without
prelink there's a predictable regression, from 55 to 140 ms.  On C++ hello
world, I get:
            PLT   no-PLT  PLT+BIND_NOW
[32bit]  430 ms   535 ms  590 ms
[64bit]  410 ms   495 ms  555 ms

So no-PLT is >20% slower than default, but already >10% faster when non-lazy
binding is forced.

On tramp3d compilation with -O2 -g I get:
            PLT   no-PLT
[32bit]  49.0 s   43.3 s
[64bit]  41.6 s   36.8 s

So on long-running compiles -fno-plt is a very significant win.  Note that I'm
using Clang as (perhaps extreme) example of PIC-call-intensive code, but the
argument about -fno-plt being useful for performance should apply generally.

When looking at code size changes, there's a 1% improvement on 32-bit
libstdc++ and a small regression on 64-bit.  On LLVM/Clang, there's overall size
regression on both 32-bit and 64-bit; I've tried to analyze it and so far came
up with one possible cause, which is detailed in IRA REG_EQUIV patch.

Thanks.
Alexander

^ permalink raw reply	[flat|nested] 106+ messages in thread

end of thread, other threads:[~2015-08-07 13:28 UTC | newest]

Thread overview: 106+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-04 16:38 PIC calls without PLT, generic implementation Alexander Monakov
2015-05-04 16:38 ` [RFC PATCH] ira: accept loads via argp rtx in validate_equiv_mem Alexander Monakov
2015-05-04 17:37   ` Jeff Law
2015-05-04 16:38 ` [PATCH i386] PR65753: allow PIC tail calls via function pointers Alexander Monakov
2015-05-10 16:37   ` Jan Hubicka
2015-05-11 16:11     ` Alexander Monakov
2015-05-04 16:38 ` [PATCH i386] Extend sibcall peepholes to allow source in %eax Alexander Monakov
2015-05-10 16:54   ` Jan Hubicka
2015-05-11 17:50     ` Alexander Monakov
2015-05-11 18:00       ` Jan Hubicka
2015-05-11 19:46         ` Uros Bizjak
2015-05-11 19:48           ` Jeff Law
2015-05-11 20:16             ` Jan Hubicka
2015-05-13 19:05               ` Alexander Monakov
2015-05-13 20:04                 ` Jan Hubicka
2015-05-14 17:36                   ` Alexander Monakov
2015-05-04 16:38 ` [PATCH i386] Move CLOBBERED_REGS earlier in register class list Alexander Monakov
2015-05-10 16:44   ` Jan Hubicka
2015-05-10 17:51     ` Uros Bizjak
2015-05-10 18:09       ` Uros Bizjak
2015-05-11 16:26         ` Alexander Monakov
2015-05-11 16:30           ` Uros Bizjak
2015-05-04 16:38 ` [PATCH i386] Allow sibcalls in no-PLT PIC Alexander Monakov
2015-05-15 16:37   ` Alexander Monakov
2015-05-15 16:48     ` H.J. Lu
2015-05-15 20:08       ` Jan Hubicka
2015-05-15 20:23         ` H.J. Lu
2015-05-15 20:35           ` Rich Felker
2015-05-15 20:37             ` H.J. Lu
2015-05-15 20:45               ` Rich Felker
2015-05-15 22:16                 ` H.J. Lu
2015-05-15 23:14                   ` Jan Hubicka
2015-05-15 23:30                     ` H.J. Lu
2015-05-15 23:35                       ` H.J. Lu
2015-05-15 23:44                         ` H.J. Lu
2015-05-16  0:18                           ` Rich Felker
2015-05-16 14:33                             ` H.J. Lu
2015-05-16 19:03                               ` H.J. Lu
2015-05-16 19:32                                 ` Rich Felker
2015-05-16 23:23                                   ` H.J. Lu
2015-05-15 23:49                       ` Rich Felker
2015-05-19 14:48                         ` Michael Matz
2015-05-19 15:11                           ` Jeff Law
2015-05-19 16:03                             ` Michael Matz
2015-05-19 19:11                               ` Rich Felker
2015-05-19 18:08                           ` Rich Felker
2015-05-19 19:03                             ` Richard Henderson
2015-05-19 19:10                               ` H.J. Lu
2015-05-19 19:17                                 ` Richard Henderson
2015-05-19 19:20                                   ` H.J. Lu
2015-05-19 19:54                                     ` Richard Henderson
2015-05-19 20:27                                     ` Rich Felker
2015-05-19 20:44                                       ` H.J. Lu
2015-05-19 21:28                                         ` Rich Felker
2015-05-20  0:52                                           ` H.J. Lu
2015-05-20  1:09                                             ` Rich Felker
2015-05-22 19:32                                               ` Richard Henderson
2015-05-19 19:48                               ` Rich Felker
2015-05-19 20:16                                 ` Richard Henderson
2015-05-20 12:13                               ` Michael Matz
2015-05-20 12:40                                 ` H.J. Lu
2015-05-20 14:17                                 ` Rich Felker
2015-05-20 14:33                                   ` Michael Matz
2015-05-18 18:25         ` Alexander Monakov
2015-05-18 19:03           ` Jan Hubicka
2015-05-04 16:38 ` [PATCH] Expand PIC calls without PLT with -fno-plt Alexander Monakov
2015-05-04 17:34   ` Jeff Law
2015-05-04 17:40     ` Jakub Jelinek
2015-05-04 17:42       ` Jeff Law
2015-05-06  3:08         ` Rich Felker
2015-05-10 17:07           ` Jan Hubicka
2015-05-06 15:25         ` Alexander Monakov
2015-05-06 15:46           ` Jakub Jelinek
2015-05-06 15:55             ` Jeff Law
2015-05-06 16:44             ` Alexander Monakov
2015-05-06 17:35               ` Rich Felker
2015-05-06 18:26                 ` H.J. Lu
2015-05-06 18:37                   ` Rich Felker
2015-05-06 18:45                     ` H.J. Lu
2015-05-06 19:01                       ` Rich Felker
2015-05-06 19:05                         ` H.J. Lu
2015-05-06 19:18                           ` Rich Felker
2015-05-06 19:24                             ` H.J. Lu
2015-05-11 11:48                             ` Michael Matz
2015-05-11 14:20                               ` Rich Felker
2015-05-07 18:22           ` Jeff Law
2015-05-07 19:13             ` H.J. Lu
2015-05-10 16:59   ` Jan Hubicka
2015-05-11 20:36     ` Jeff Law
2015-05-11 20:55       ` H.J. Lu
2015-05-11 22:13         ` Jan Hubicka
2015-06-22 15:52   ` Jiong Wang
2015-06-22 18:18     ` Alexander Monakov
2015-06-23  8:41       ` Ramana Radhakrishnan
2015-06-23 10:43         ` Alexander Monakov
2015-06-23 13:28         ` Jeff Law
2015-07-16 10:37           ` [AArch64] Tighten direct call pattern to repair -fno-plt Jiong Wang
2015-07-16 10:47             ` Alexander Monakov
2015-07-16 10:48               ` Jiong Wang
2015-07-21 12:52                 ` [AArch64][sibcall]Tighten " Jiong Wang
2015-08-04  9:50                   ` James Greenhalgh
2015-08-06 16:18                     ` [COMMITTED][AArch64][sibcall]Tighten " Jiong Wang
2015-08-07  8:22                       ` James Greenhalgh
2015-08-07 13:28                         ` Jiong Wang
2015-08-04  9:50             ` [AArch64] Tighten " James Greenhalgh
2015-08-06 16:16               ` [COMMITTED][AArch64] " Jiong Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).