[PATCH] D137707: [WIP] Move "auto-init" instructions to the dominator of their users

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 17 12:02:07 PST 2022


nickdesaulniers added a comment.

I tested D137707 <https://reviews.llvm.org/D137707> Diff 475770 against an x86_64 defconfig build of the Linux kernel (commit 81ac25651a62 ("Merge tag 'nfsd-6.1-5' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux")), which sets `CONFIG_INIT_STACK_ALL_ZERO=y`.  Booted fine.

  $ du -h vmlinux.orig vmlinux.D137707.475770
  63M	vmlinux.orig
  63M	vmlinux.D137707.475770
  $ bloaty vmlinux.D137707.475770 -- vmlinux.orig
      FILE SIZE        VM SIZE    
   --------------  -------------- 
    +0.0%    +336  [ = ]       0    .rela.orc_unwind_ip
    +0.0%    +144  [ = ]       0    .rela.text
    +2.6%    +141  +2.6%    +141    [LOAD #3 [RWX]]
    +0.0%     +84  +0.0%     +84    .orc_unwind
    +0.0%     +56  +0.0%     +56    .orc_unwind_ip
    +0.0%     +24  [ = ]       0    .rela.smp_locks
    +0.3%      +3  [ = ]       0    .shstrtab
    -0.0%     -11  [ = ]       0    .strtab
    -0.0%     -24  [ = ]       0    .rela.return_sites
    -0.0%     -24  [ = ]       0    .symtab
    -8.8%    -140  -8.8%    -140    [LOAD #1 [RW]]
    -0.0%    -141  -0.0%    -141    .init.text
    +0.0%    +448  [ = ]       0    TOTAL
  $ llvm-readelf -S vmlinux.orig
  ...
    [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  ...
    [ 1] .text             PROGBITS        ffffffff81000000 200000 10032cb 00  AX  0   0 4096
  ...
  $ llvm-readelf -S vmlinux.D137707.475770
  ...
    [ 1] .text             PROGBITS        ffffffff81000000 200000 10032cb 00  AX  0   0 4096

So it appears that this patch made no difference to the size of the `.text` section. I triple checked this w/ and w/o D137707 <https://reviews.llvm.org/D137707> applied.

When I build with `make LLVM=1 -j128 KCFLAGS="-mllvm -stats"`, then process the stats from `move-auto-init`, I observe 49810 moves!  Feel free to add that measurement into the commit description.

  $ make LLVM=1 -j128 KCFLAGS="-mllvm -stats" &> log.txt
  $ grep move-auto-init log.txt | tr -s ' ' | cut -d ' ' -f 2 | python3 -c "import sys; print(sum((float(l) for l in sys.stdin)))"
  49810.0
  # Triple check with sed+bc rather than python3
  $ grep move-auto-init log.txt | tr -s ' ' | cut -d ' ' -f 2 | sed ':a;N;s/\n/+/;ta' |bc    
  49810

Please let me know if there's any other measurements you'd like me to make.

Also, it might be nice if the tests demonstrated diffs against existing (or precommitted changes) to better demonstrate how this pass changes the generated code.  Mind breaking the newly added tests into 2 patches:

1. child patch that adds them BEFORE this patch
2. rebase this patch on that to demonstrate how this patch differs?



================
Comment at: llvm/lib/Passes/PassBuilderPipelines.cpp:886
   EarlyFPM.addPass(SimplifyCFGPass());
+  EarlyFPM.addPass(MoveAutoInitPass());
   EarlyFPM.addPass(SROAPass());
----------------
Is it possible to skip this pass if `-ftrivial-auto-var-init=zero` wasn't specified?


================
Comment at: llvm/lib/Transforms/Utils/MoveAutoInit.cpp:92
+
+    if (!hasAutoInitMetadata(I))
+      continue;
----------------
is there a faster way to do this rather than having to scan the metadata of every operand?


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

https://reviews.llvm.org/D137707



More information about the llvm-commits mailing list