Skip to content

Commit d9ae078

Browse files
committed
[WebAssembly] Disable register coalescing at -O1
This disables `RegisterCoalescer` pass at -O1, which currently runs for all levels except for -O0, as a part of common optimization pipeline. `RegisterCoalescer` pass degrades Wasm debug info quality by a significant margin. When I use `LiveDebugValue` analysis, disabling this increases the average PC ranges covered by 15% on Emscripten core benchmarks (52% -> 66.8%). (Our code is currently not using `LiveDebugValues` analysis at the moment, and the experiment was done on a local setting that enabled it. I'm planning to upstream it soon.) In Emscripten core benchmarks, disabling this at -O1 causes +4.5% in code size and +1% in the number of locals. The number of globals stays the same. I believe this tradeoff is acceptable given that -O1 is not usually used in production builds and is often used for debugging when the application size is very large. The plan is to investigate and fix what's causing the degradation in that pass, but for now disabling it seems like a low-hanging quick fix. Reviewed By: dschuff Differential Revision: https://reviews.llvm.org/D138455
1 parent 5dad4c6 commit d9ae078

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ class WebAssemblyPassConfig final : public TargetPassConfig {
323323
void addIRPasses() override;
324324
void addISelPrepare() override;
325325
bool addInstSelector() override;
326+
void addOptimizedRegAlloc() override;
326327
void addPostRegAlloc() override;
327328
bool addGCPasses() override { return false; }
328329
void addPreEmitPass() override;
@@ -480,6 +481,19 @@ bool WebAssemblyPassConfig::addInstSelector() {
480481
return false;
481482
}
482483

484+
void WebAssemblyPassConfig::addOptimizedRegAlloc() {
485+
// Currently RegisterCoalesce degrades wasm debug info quality by a
486+
// significant margin. As a quick fix, disable this for -O1, which is often
487+
// used for debugging large applications. Disabling this increases code size
488+
// of Emscripten core benchmarks by ~5%, which is acceptable for -O1, which is
489+
// usually not used for production builds.
490+
// TODO Investigate why RegisterCoalesce degrades debug info quality and fix
491+
// it properly
492+
if (getOptLevel() == CodeGenOpt::Less)
493+
disablePass(&RegisterCoalescerID);
494+
TargetPassConfig::addOptimizedRegAlloc();
495+
}
496+
483497
void WebAssemblyPassConfig::addPostRegAlloc() {
484498
// TODO: The following CodeGen passes don't currently support code containing
485499
// virtual registers. Consider removing their restrictions and re-enabling
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llc < %s -O1 --debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O1
2+
; RUN: llc < %s -O2 --debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O2
3+
4+
; Test if RegisterCoalesce pass is disabled in -O1.
5+
6+
; O1-NOT: Simple Register Coalescing
7+
; O2: Simple Register Coalescing
8+
target triple = "wasm32-unknown-unknown"
9+
10+
define void @test() {
11+
ret void
12+
}

0 commit comments

Comments
 (0)