binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Simple/Local Dead Store Elimination

Open kripken opened this issue 3 years ago • 4 comments

This begins to add dead store elimination to the optimizer. It provides the basic infrastructure, and implements simple and local DSE on top. All that can do so far is remove obviously-trampled stores inside a function. Future work will add whole-program analysis, and more things than just removing dead stores (like forwarding loads).

This does show how the single framework can handle multiple notions of "stores" and "loads". It uses almost the exact same code to optimize

  • Globals: global.set/get
  • Memory: *.store, *.load
  • GC heap: struct.set/get

This level of generality has some downsides to speed, but the simplicity is hopefully worth it, see details in comments.

This does not enable the pass by default. Until it is more powerful, there is little point, and also it will likely need to be tuned for speed (as it does not have a simple guarantee of running in linear time).

See: #3772

kripken avatar May 04 '21 20:05 kripken

(added a small unreachability fix for a fuzzer issue)

kripken avatar May 10 '21 16:05 kripken

@kripken Hi, is there any chance of merge with main branch? Or is something blocking this PR?

MaxGraey avatar Jun 29 '22 15:06 MaxGraey

@MaxGraey The problem is that I haven't seen this help in a significant way on benchmarks. It would be significant work to get this done and landed, so I'm focusing on other things for now (like #4598).

kripken avatar Jul 02 '22 00:07 kripken

Thanks! Yes, I did not expect serious performance improvements because Wasm engines (except interpreted ones) have similar optimization pass, but this pass in theory could improve module size, at least for some non-LLVM languages.

MaxGraey avatar Jul 02 '22 04:07 MaxGraey