[go] cmd/compile: eliminate redundant sign-extensions for wasm

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Mar 17, 2026, 2:49:32 PM (yesterday) Mar 17
to George Adams, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Carlos Amedee, Keith Randall, Keith Randall, Go LUCI, Quim Muntal, David Chase, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
cmd/compile: eliminate redundant sign-extensions for wasm

Add rules to eliminate redundant I64Extend sign-extension operations
in the wasm backend:

Idempotent (applying the same extend twice is redundant):

(I64Extend32S (I64Extend32S x)) => (I64Extend32S x)
(I64Extend16S (I64Extend16S x)) => (I64Extend16S x)
(I64Extend8S (I64Extend8S x)) => (I64Extend8S x)

Narrower-subsumes-wider (a narrower sign-extend already determines
all the bits that a wider one would set):

(I64Extend32S (I64Extend16S x)) => (I64Extend16S x)
(I64Extend32S (I64Extend8S x)) => (I64Extend8S x)
(I64Extend16S (I64Extend8S x)) => (I64Extend8S x)

These patterns arise from nested sub-word type conversions. For
example, converting int8 -> int16 -> int32 -> int64 lowers to
I64Extend8S -> I64Extend16S -> I64Extend32S, but the I64Extend8S
alone is sufficient since it already sign-extends from 8 to 64 bits.
Cq-Include-Trybots: luci.golang.try:gotip-wasip1-wasm_wasmtime,gotip-wasip1-wasm_wazero
Change-Id: I1637687df31893b1ffa36915a3bd2e10d455f4ef
Reviewed-by: Carlos Amedee <car...@golang.org>
Auto-Submit: Keith Randall <k...@golang.org>
Reviewed-by: Keith Randall <k...@golang.org>
Reviewed-by: Keith Randall <k...@google.com>
Files:
  • M src/cmd/compile/internal/ssa/_gen/Wasm.rules
  • M src/cmd/compile/internal/ssa/rewriteWasm.go
Change size: M
Delta: 2 files changed, 92 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Carlos Amedee, +1 by Keith Randall, +2 by Keith Randall
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I1637687df31893b1ffa36915a3bd2e10d455f4ef
Gerrit-Change-Number: 754040
Gerrit-PatchSet: 2
Gerrit-Owner: George Adams <georgea...@gmail.com>
Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Quim Muntal <quimm...@gmail.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages