[all-commits] [llvm/llvm-project] cd4635: [WebAssembly] Enable a limited amount of stackific...

SingleAccretion via All-commits all-commits at lists.llvm.org
Tue Jun 24 11:41:08 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: cd46354dbd10820158edabe14dbd49d9f9010722
      https://github.com/llvm/llvm-project/commit/cd46354dbd10820158edabe14dbd49d9f9010722
  Author: SingleAccretion <62474226+SingleAccretion at users.noreply.github.com>
  Date:   2025-06-24 (Tue, 24 Jun 2025)

  Changed paths:
    M llvm/lib/Target/WebAssembly/WebAssembly.h
    M llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
    M llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
    M llvm/test/CodeGen/WebAssembly/PR40172.ll
    M llvm/test/CodeGen/WebAssembly/PR41841.ll
    A llvm/test/CodeGen/WebAssembly/debug-code-stackification.ll
    M llvm/test/CodeGen/WebAssembly/pr51651.ll
    M llvm/test/CodeGen/WebAssembly/signext-zeroext-callsite.ll
    M llvm/test/CodeGen/WebAssembly/suboptimal-compare.ll

  Log Message:
  -----------
  [WebAssembly] Enable a limited amount of stackification for debug code (#136510)

This change is a step towards fixing one long-standing problem with
LLVM's debug WASM codegen: excessive use of locals. One local for each
temporary value in IR (roughly speaking).

This has a lot of problems:
1) It makes it easy to hit engine limitations of 50K locals with certain
code patterns and large functions.
2) It makes for larger binaries that are slower to load and slower to
compile to native code.
3) It makes certain compilation strategies (spill all WASM locals to
stack, for example) for debug code excessively expensive and makes debug
WASM code either run very slow, or be less debuggable.
4) It slows down LLVM itself.

This change addresses these partially by running a limited version of
the stackification pass for unoptimized code, one that gets rid of the
most 'obviously' unnecessary locals.

Care needs to be taken to not impact LLVM's ability to produce high
quality debug variable locations with this pass. To that end:
1) We only allow stackification when it doesn't require moving any
instructions.
2) We disable stackification of any locals that are used in
DEBUG_VALUEs, or as a frame base.
I have verified on a moderately large example that the baseline and the
diff produce the same kinds (local/global/stack) of locations, and the
only differences are due to the shifting of instruction offsets, with
many local.[get|set]s not being present anymore.

Even with this quite conservative approach, the results are pretty good:
1) 30% reduction in raw code size, up to 10x reduction in the number of
locals for select large methods (~1000 => ~100).
2) ~10% reduction in instructions retired for an "llc -O0" run on a
moderately sized input.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list