diff options
| author | David Chase <drchase@google.com> | 2025-12-11 14:27:10 -0500 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2026-03-01 11:58:20 -0800 |
| commit | d51d4d75a67a5c0228ed55107a809f8f377c5949 (patch) | |
| tree | b564633786fcb29aa6ff35ab3b606bfa25cc52d8 /src/cmd | |
| parent | 425a88193ca39e82dc3dbcae22b98dbdfd98a04c (diff) | |
| download | go-d51d4d75a67a5c0228ed55107a809f8f377c5949.tar.xz | |
cmd/compile: (wasm) optimize float32(round64(float64(x)))
Not a fix because there are other architectures
still to be done.
Updates #75463.
Change-Id: Ia5233c2b6c5f4439e269950efdd851e72e8e7ff6
Reviewed-on: https://go-review.googlesource.com/c/go/+/730160
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/compile/internal/ssa/_gen/Wasm.rules | 3 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssa/rewriteWasm.go | 117 |
2 files changed, 120 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/Wasm.rules b/src/cmd/compile/internal/ssa/_gen/Wasm.rules index 6028152253..4b533df6a0 100644 --- a/src/cmd/compile/internal/ssa/_gen/Wasm.rules +++ b/src/cmd/compile/internal/ssa/_gen/Wasm.rules @@ -349,6 +349,9 @@ (Abs ...) => (F64Abs ...) (Copysign ...) => (F64Copysign ...) +(F32DemoteF64 (F64(Sqrt|Trunc|Ceil|Floor|Nearest|Abs) (F64PromoteF32 x))) => (F32(Sqrt|Trunc|Ceil|Floor|Nearest|Abs) x) +(F32DemoteF64 (F64Copysign (F64PromoteF32 x) (F64PromoteF32 y))) => (F32Copysign x y) + (Sqrt32 ...) => (F32Sqrt ...) (Ctz64 ...) => (I64Ctz ...) diff --git a/src/cmd/compile/internal/ssa/rewriteWasm.go b/src/cmd/compile/internal/ssa/rewriteWasm.go index faba41b3e5..f7fe8fa7e2 100644 --- a/src/cmd/compile/internal/ssa/rewriteWasm.go +++ b/src/cmd/compile/internal/ssa/rewriteWasm.go @@ -599,6 +599,8 @@ func rewriteValueWasm(v *Value) bool { case OpWB: v.Op = OpWasmLoweredWB return true + case OpWasmF32DemoteF64: + return rewriteValueWasm_OpWasmF32DemoteF64(v) case OpWasmF64Add: return rewriteValueWasm_OpWasmF64Add(v) case OpWasmF64Mul: @@ -3617,6 +3619,121 @@ func rewriteValueWasm_OpStore(v *Value) bool { } return false } +func rewriteValueWasm_OpWasmF32DemoteF64(v *Value) bool { + v_0 := v.Args[0] + // match: (F32DemoteF64 (F64Sqrt (F64PromoteF32 x))) + // result: (F32Sqrt x) + for { + if v_0.Op != OpWasmF64Sqrt { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpWasmF64PromoteF32 { + break + } + x := v_0_0.Args[0] + v.reset(OpWasmF32Sqrt) + v.AddArg(x) + return true + } + // match: (F32DemoteF64 (F64Trunc (F64PromoteF32 x))) + // result: (F32Trunc x) + for { + if v_0.Op != OpWasmF64Trunc { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpWasmF64PromoteF32 { + break + } + x := v_0_0.Args[0] + v.reset(OpWasmF32Trunc) + v.AddArg(x) + return true + } + // match: (F32DemoteF64 (F64Ceil (F64PromoteF32 x))) + // result: (F32Ceil x) + for { + if v_0.Op != OpWasmF64Ceil { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpWasmF64PromoteF32 { + break + } + x := v_0_0.Args[0] + v.reset(OpWasmF32Ceil) + v.AddArg(x) + return true + } + // match: (F32DemoteF64 (F64Floor (F64PromoteF32 x))) + // result: (F32Floor x) + for { + if v_0.Op != OpWasmF64Floor { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpWasmF64PromoteF32 { + break + } + x := v_0_0.Args[0] + v.reset(OpWasmF32Floor) + v.AddArg(x) + return true + } + // match: (F32DemoteF64 (F64Nearest (F64PromoteF32 x))) + // result: (F32Nearest x) + for { + if v_0.Op != OpWasmF64Nearest { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpWasmF64PromoteF32 { + break + } + x := v_0_0.Args[0] + v.reset(OpWasmF32Nearest) + v.AddArg(x) + return true + } + // match: (F32DemoteF64 (F64Abs (F64PromoteF32 x))) + // result: (F32Abs x) + for { + if v_0.Op != OpWasmF64Abs { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpWasmF64PromoteF32 { + break + } + x := v_0_0.Args[0] + v.reset(OpWasmF32Abs) + v.AddArg(x) + return true + } + // match: (F32DemoteF64 (F64Copysign (F64PromoteF32 x) (F64PromoteF32 y))) + // result: (F32Copysign x y) + for { + if v_0.Op != OpWasmF64Copysign { + break + } + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpWasmF64PromoteF32 { + break + } + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpWasmF64PromoteF32 { + break + } + y := v_0_1.Args[0] + v.reset(OpWasmF32Copysign) + v.AddArg2(x, y) + return true + } + return false +} func rewriteValueWasm_OpWasmF64Add(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] |
