[PATCH] D120305: [Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 26 12:55:18 PST 2022


MaskRay added a comment.

In D120305#3344938 <https://reviews.llvm.org/D120305#3344938>, @nikic wrote:

> Hm, it looks like enabling PIE has a pretty big negative compile-time impact, with a 20% regression on sqlite3: http://llvm-compile-time-tracker.com/compare.php?from=611122892e6d5813444bdd0e1fbe0a96f6e09779&to=3c4ed02698afec021c6bca80740d1e58e3ee019e&stat=instructions Code-size on kimwitu++ regresses by 13%.
>
> Is that kind of impact expected?

Many groups build sqlite3 with -fPIC. -fPIC and -fPIE have similar compile time.
The metric on llvm-compile-time-tracker.com is related to `llvm-test-suite/CTMark/sqlite3`, which just focuses on (without the CMake patch) `-fno-pic` performance.

(
I checked run time, no big difference.

  % hyperfine --warmup 2 --min-runs 16 "/tmp/c/sqlite3.nopie -init sqlite3rc :memory: < commands"                         
  Benchmark 1: /tmp/c/sqlite3.nopie -init sqlite3rc :memory: < commands
    Time (mean ± σ):      2.068 s ±  0.011 s    [User: 2.044 s, System: 0.024 s]
    Range (min … max):    2.044 s …  2.085 s    16 runs
  
  % hyperfine --warmup 2 --min-runs 16 "/tmp/c/sqlite3.pie -init sqlite3rc :memory: < commands"  
  Benchmark 1: /tmp/c/sqlite3.pie -init sqlite3rc :memory: < commands
    Time (mean ± σ):      2.053 s ±  0.015 s    [User: 2.034 s, System: 0.018 s]
    Range (min … max):    2.027 s …  2.080 s    16 runs

)

About compile time,

I run `=time -f "CPU: %Us\tReal: %es\tRAM: %MKB" /tmp/out/custom1/bin/clang -DNDEBUG -O3 -DNDEBUG -w -Werror=date-time -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -I. -o CTMark/sqlite3/CMakeFiles/sqlite3.dir/sqlite3.c.o -c ~/Dev/llvm-test-suite/CTMark/sqlite3/sqlite3.c -ftime-report` with -fno-pie/-fpie/-fpic to get some insight.

The IR has minor difference but pie's is slightly larger:

  % wc -l nopie.ll pie.ll
    157975 nopie.ll
    159675 pie.ll
  ...

If someone wants to investigate, `sqlite3Parser` changes a lot from -fno-pic to -fPIE, but that looks organic changes to me.
-ftime-report comparison suggests that every pass is slightly slower with -fPIE. ModuleInlinerWrapperPass and DevirtSCCRepeatedPass contribute most of the slowness.

  -fno-pic -ftime-report
     ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
     5.1753 ( 28.1%)   0.2359 ( 27.5%)   5.4112 ( 28.0%)   5.4123 ( 28.1%)  ModuleInlinerWrapperPass
     5.1447 ( 27.9%)   0.2309 ( 26.9%)   5.3755 ( 27.8%)   5.3767 ( 27.9%)  DevirtSCCRepeatedPass
     1.8716 ( 10.1%)   0.0936 ( 10.9%)   1.9652 ( 10.2%)   1.9613 ( 10.2%)  InstCombinePass
     0.7674 (  4.2%)   0.0254 (  3.0%)   0.7928 (  4.1%)   0.7921 (  4.1%)  GVNPass
     0.4563 (  2.5%)   0.0288 (  3.4%)   0.4851 (  2.5%)   0.4844 (  2.5%)  InlinerPass
     0.4194 (  2.3%)   0.0174 (  2.0%)   0.4368 (  2.3%)   0.4359 (  2.3%)  MemorySSAAnalysis
     0.3399 (  1.8%)   0.0191 (  2.2%)   0.3589 (  1.9%)   0.3578 (  1.9%)  SimplifyCFGPass
     0.3206 (  1.7%)   0.0143 (  1.7%)   0.3349 (  1.7%)   0.3354 (  1.7%)  BlockFrequencyAnalysis
     0.2985 (  1.6%)   0.0081 (  0.9%)   0.3065 (  1.6%)   0.3061 (  1.6%)  CorrelatedValuePropagationPass
     0.2608 (  1.4%)   0.0158 (  1.8%)   0.2767 (  1.4%)   0.2763 (  1.4%)  EarlyCSEPass



  -fpie -ftime-report
     ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
     7.8109 ( 29.2%)   0.2239 ( 26.8%)   8.0347 ( 29.1%)   8.0363 ( 29.2%)  ModuleInlinerWrapperPass
     7.7752 ( 29.1%)   0.2230 ( 26.6%)   7.9981 ( 29.0%)   7.9997 ( 29.0%)  DevirtSCCRepeatedPass
     2.5352 (  9.5%)   0.0807 (  9.6%)   2.6158 (  9.5%)   2.6114 (  9.5%)  InstCombinePass
     1.2792 (  4.8%)   0.0162 (  1.9%)   1.2954 (  4.7%)   1.2948 (  4.7%)  GVNPass
     0.6529 (  2.4%)   0.0157 (  1.9%)   0.6686 (  2.4%)   0.6674 (  2.4%)  MemorySSAAnalysis
     0.6048 (  2.3%)   0.0261 (  3.1%)   0.6309 (  2.3%)   0.6306 (  2.3%)  InlinerPass
     0.4625 (  1.7%)   0.0126 (  1.5%)   0.4751 (  1.7%)   0.4743 (  1.7%)  CorrelatedValuePropagationPass
     0.4541 (  1.7%)   0.0160 (  1.9%)   0.4701 (  1.7%)   0.4690 (  1.7%)  SimplifyCFGPass
     0.3981 (  1.5%)   0.0124 (  1.5%)   0.4105 (  1.5%)   0.4101 (  1.5%)  EarlyCSEPass



- -fno-pie: Time (mean ± σ):     11.999 s ±  0.043 s
- -fpie: Time (mean ± σ):     14.643 s ±  0.073 s
- -fno-pie -flegacy-pass-manager: Time (mean ± σ):     16.831 s ±  0.027 s
- -fpie -flegacy-pass-manager: Time (mean ± σ):     16.887 s ±  0.099 s


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120305/new/

https://reviews.llvm.org/D120305



More information about the cfe-commits mailing list