diff options
author | Agniva De Sarker <agnivade@yahoo.co.in> | 2020-08-08 15:19:42 +0530 |
---|---|---|
committer | Agniva De Sarker <agniva.quicksilver@gmail.com> | 2020-08-22 12:35:47 +0000 |
commit | 8acbe4c0b392840062cf882886e2424c5f07a665 (patch) | |
tree | a0860ba30c561cd545bb741609f4a9d7ca1e39bb /src/cmd/compile/internal/ssa/rewriteWasm.go | |
parent | 13e41bcde8c788224f4896503b56d42614e0bf97 (diff) | |
download | go-8acbe4c0b392840062cf882886e2424c5f07a665.tar.gz go-8acbe4c0b392840062cf882886e2424c5f07a665.zip |
cmd/compile: optimize unsigned comparisons with 0/1 on wasm
Updates #21439
Change-Id: I0fbcde6e0c2fc368fe686b271670f9d8be4a7900
Reviewed-on: https://go-review.googlesource.com/c/go/+/247557
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Richard Musiol <neelance@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewriteWasm.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/rewriteWasm.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteWasm.go b/src/cmd/compile/internal/ssa/rewriteWasm.go index 16e6f96917..52b6f6bfc7 100644 --- a/src/cmd/compile/internal/ssa/rewriteWasm.go +++ b/src/cmd/compile/internal/ssa/rewriteWasm.go @@ -591,6 +591,8 @@ func rewriteValueWasm(v *Value) bool { return rewriteValueWasm_OpWasmI64Eq(v) case OpWasmI64Eqz: return rewriteValueWasm_OpWasmI64Eqz(v) + case OpWasmI64LeU: + return rewriteValueWasm_OpWasmI64LeU(v) case OpWasmI64Load: return rewriteValueWasm_OpWasmI64Load(v) case OpWasmI64Load16S: @@ -605,6 +607,8 @@ func rewriteValueWasm(v *Value) bool { return rewriteValueWasm_OpWasmI64Load8S(v) case OpWasmI64Load8U: return rewriteValueWasm_OpWasmI64Load8U(v) + case OpWasmI64LtU: + return rewriteValueWasm_OpWasmI64LtU(v) case OpWasmI64Mul: return rewriteValueWasm_OpWasmI64Mul(v) case OpWasmI64Ne: @@ -3824,6 +3828,37 @@ func rewriteValueWasm_OpWasmI64Eqz(v *Value) bool { } return false } +func rewriteValueWasm_OpWasmI64LeU(v *Value) bool { + v_1 := v.Args[1] + v_0 := v.Args[0] + b := v.Block + typ := &b.Func.Config.Types + // match: (I64LeU x (I64Const [0])) + // result: (I64Eqz x) + for { + x := v_0 + if v_1.Op != OpWasmI64Const || auxIntToInt64(v_1.AuxInt) != 0 { + break + } + v.reset(OpWasmI64Eqz) + v.AddArg(x) + return true + } + // match: (I64LeU (I64Const [1]) x) + // result: (I64Eqz (I64Eqz x)) + for { + if v_0.Op != OpWasmI64Const || auxIntToInt64(v_0.AuxInt) != 1 { + break + } + x := v_1 + v.reset(OpWasmI64Eqz) + v0 := b.NewValue0(v.Pos, OpWasmI64Eqz, typ.Bool) + v0.AddArg(x) + v.AddArg(v0) + return true + } + return false +} func rewriteValueWasm_OpWasmI64Load(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] @@ -4070,6 +4105,37 @@ func rewriteValueWasm_OpWasmI64Load8U(v *Value) bool { } return false } +func rewriteValueWasm_OpWasmI64LtU(v *Value) bool { + v_1 := v.Args[1] + v_0 := v.Args[0] + b := v.Block + typ := &b.Func.Config.Types + // match: (I64LtU (I64Const [0]) x) + // result: (I64Eqz (I64Eqz x)) + for { + if v_0.Op != OpWasmI64Const || auxIntToInt64(v_0.AuxInt) != 0 { + break + } + x := v_1 + v.reset(OpWasmI64Eqz) + v0 := b.NewValue0(v.Pos, OpWasmI64Eqz, typ.Bool) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (I64LtU x (I64Const [1])) + // result: (I64Eqz x) + for { + x := v_0 + if v_1.Op != OpWasmI64Const || auxIntToInt64(v_1.AuxInt) != 1 { + break + } + v.reset(OpWasmI64Eqz) + v.AddArg(x) + return true + } + return false +} func rewriteValueWasm_OpWasmI64Mul(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] |