JIT: rewrite wasm local.set/local.get as local.tee - #131513
Conversation
Emitter peephole. Shrinks the R2R corelib code section by 2.56%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@adamperlin PTAL |
|
Azure Pipelines: Successfully started running 6 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This change adds a small WASM emitter peephole optimization in CoreCLR’s JIT to reduce instruction count by folding a local.set immediately followed by a local.get of the same local into a single local.tee.
Changes:
- Add an optimization in
emitter::emitIns_Ito rewritelocal.set N; local.get Nintolocal.tee Nwhen optimizations are enabled and peepholing the last instruction is safe.
|
Nice win. Verified the mechanics hold up: One complementary peephole you may want to fold in while you're here:
https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/codegenwasm.cpp#L804-L816 The fold is unconditionally valid ( void emitter::emitIns(instruction ins)
{
// Rewrite `local.tee N; drop` as `local.set N`.
//
if ((ins == INS_drop) && m_compiler->opts.OptimizationEnabled() && emitCanPeepholeLastIns() &&
(emitLastIns->idIns() == INS_local_tee))
{
JITDUMP("\n -- rewriting 'local.tee' as 'local.set' since its result is immediately dropped.\n");
emitLastIns->idIns(INS_local_set);
return;
}
instrDesc* id = emitNewInstrSmall(EA_8BYTE);There's a larger adjacent opportunity too, though it's clearly not a drive-by: five sites emit Note This comment was generated by GitHub Copilot. |
There doesn't seem to be much savings here... |
Yeah, I know this pattern comes up in hwintrinsic codegen for the jump tables because we |
Emitter peephole. Shrinks the R2R corelib code section by 2.56%.