From c3c3c5f87af07bfcd943129d87e3d3f2aefb10f3 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 25 Jun 2024 09:20:15 -0700 Subject: [PATCH] compiler: removes unnecessary code paths (#2266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes the unnecessary code paths in a various places, and the below is the result: ``` goos: darwin goarch: arm64 pkg: github.com/tetratelabs/wazero │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Compilation/wazero-10 1.634 ± 0% 1.626 ± 0% -0.51% (p=0.002 n=6) Compilation/zig-10 3.588 ± 0% 3.538 ± 2% ~ (p=0.065 n=6) Compilation/zz-10 15.25 ± 0% 14.87 ± 1% -2.46% (p=0.002 n=6) geomean 4.472 4.406 -1.46% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ Compilation/wazero-10 271.2Mi ± 0% 271.2Mi ± 0% ~ (p=1.000 n=6) Compilation/zig-10 596.3Mi ± 0% 596.3Mi ± 0% ~ (p=0.699 n=6) Compilation/zz-10 528.9Mi ± 0% 528.9Mi ± 0% ~ (p=0.818 n=6) geomean 440.6Mi 440.6Mi +0.00% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ Compilation/wazero-10 448.5k ± 0% 448.5k ± 0% ~ (p=0.937 n=6) Compilation/zig-10 274.8k ± 0% 274.7k ± 0% ~ (p=1.000 n=6) Compilation/zz-10 618.3k ± 0% 618.4k ± 0% ~ (p=0.818 n=6) geomean 423.9k 423.9k -0.00% ``` Signed-off-by: Takeshi Yoneda --- internal/engine/wazevo/backend/regalloc/regalloc.go | 9 +++------ internal/engine/wazevo/ssa/builder.go | 4 ---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/internal/engine/wazevo/backend/regalloc/regalloc.go b/internal/engine/wazevo/backend/regalloc/regalloc.go index d02961a8a2..b30ffcec8e 100644 --- a/internal/engine/wazevo/backend/regalloc/regalloc.go +++ b/internal/engine/wazevo/backend/regalloc/regalloc.go @@ -229,9 +229,6 @@ func (s *state[I, B]) getVRegState(v VRegID) *vrState[I, B] { } func (s *state[I, B]) useRealReg(r RealReg, vr *vrState[I, B]) { - if s.regsInUse.has(r) { - panic("BUG: useRealReg: the given real register is already used") - } s.regsInUse.add(r, vr) vr.r = r s.allocatedRegSet = s.allocatedRegSet.add(r) @@ -250,16 +247,16 @@ func (s *state[I, B]) releaseRealReg(r RealReg) { func (vs *vrState[I, B]) recordReload(f Function[I, B], blk B) { vs.spilled = true var nilBlk B - if vs.lca == nilBlk { + if lca := vs.lca; lca == nilBlk { if wazevoapi.RegAllocLoggingEnabled { fmt.Printf("\t\tv%d is reloaded in blk%d,\n", vs.v.ID(), blk.ID()) } vs.lca = blk - } else { + } else if lca != blk { if wazevoapi.RegAllocLoggingEnabled { fmt.Printf("\t\tv%d is reloaded in blk%d, lca=%d\n", vs.v.ID(), blk.ID(), vs.lca.ID()) } - vs.lca = f.LowestCommonAncestor(vs.lca, blk) + vs.lca = f.LowestCommonAncestor(lca, blk) if wazevoapi.RegAllocLoggingEnabled { fmt.Printf("updated lca=%d\n", vs.lca.ID()) } diff --git a/internal/engine/wazevo/ssa/builder.go b/internal/engine/wazevo/ssa/builder.go index 0eb0fc518f..227c46ab36 100644 --- a/internal/engine/wazevo/ssa/builder.go +++ b/internal/engine/wazevo/ssa/builder.go @@ -294,10 +294,6 @@ func (b *builder) Init(s *Signature) { b.nextValueID = 0 b.reversePostOrderedBasicBlocks = b.reversePostOrderedBasicBlocks[:0] b.doneBlockLayout = false - for i := range b.valueRefCounts { - b.valueRefCounts[i] = 0 - } - b.currentSourceOffset = sourceOffsetUnknown }