diff options
author | Ben Shi <powerman1st@163.com> | 2019-08-20 09:03:41 +0000 |
---|---|---|
committer | Ben Shi <powerman1st@163.com> | 2019-08-28 02:29:25 +0000 |
commit | 731e6fc34ec1c99a72ac7c66db7a87786d918edf (patch) | |
tree | 35649dec44895480b294f2d13c4b31716bf3b834 /src/cmd/compile/internal/ssa/rewriteWasm.go | |
parent | 9c67516ed69e6c5152b9f329f240f69f27f8004b (diff) | |
download | go-731e6fc34ec1c99a72ac7c66db7a87786d918edf.tar.gz go-731e6fc34ec1c99a72ac7c66db7a87786d918edf.zip |
cmd/compile: generate Select on WASM
This CL performs the branchelim optimization on WASM with its
select instruction. And the total size of pkg/js_wasm decreased
about 80KB by this optimization.
Change-Id: I868eb146120a1cac5c4609c8e9ddb07e4da8a1d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/190957
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Richard Musiol <neelance@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewriteWasm.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/rewriteWasm.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteWasm.go b/src/cmd/compile/internal/ssa/rewriteWasm.go index 98ca6f69a3..4bded46065 100644 --- a/src/cmd/compile/internal/ssa/rewriteWasm.go +++ b/src/cmd/compile/internal/ssa/rewriteWasm.go @@ -50,6 +50,8 @@ func rewriteValueWasm(v *Value) bool { return rewriteValueWasm_OpCom64_0(v) case OpCom8: return rewriteValueWasm_OpCom8_0(v) + case OpCondSelect: + return rewriteValueWasm_OpCondSelect_0(v) case OpConst16: return rewriteValueWasm_OpConst16_0(v) case OpConst32: @@ -865,6 +867,23 @@ func rewriteValueWasm_OpCom8_0(v *Value) bool { return true } } +func rewriteValueWasm_OpCondSelect_0(v *Value) bool { + // match: (CondSelect <t> x y cond) + // cond: + // result: (Select <t> x y cond) + for { + t := v.Type + cond := v.Args[2] + x := v.Args[0] + y := v.Args[1] + v.reset(OpWasmSelect) + v.Type = t + v.AddArg(x) + v.AddArg(y) + v.AddArg(cond) + return true + } +} func rewriteValueWasm_OpConst16_0(v *Value) bool { // match: (Const16 [val]) // cond: |