diff options
author | Richard Musiol <mail@richard-musiol.de> | 2019-02-28 15:20:59 +0100 |
---|---|---|
committer | Richard Musiol <neelance@gmail.com> | 2019-02-28 15:25:42 +0000 |
commit | 72d24a7484063d1ca1113badb481f725382e39b8 (patch) | |
tree | dc5bfaf8e5d5c4317663d6e862909fc40c385411 /src/cmd/compile/internal/ssa/rewriteWasm.go | |
parent | 1f17d61026a9d83591db420ba1441c8555d2f4a0 (diff) | |
download | go-72d24a7484063d1ca1113badb481f725382e39b8.tar.gz go-72d24a7484063d1ca1113badb481f725382e39b8.zip |
cmd/compile: simplify zero ext operations on wasm
On wasm every integer is stored with 64 bits. We can do zero
extension by simply zeroing the upper bits.
Change-Id: I02c54a38b3b2b7654fff96055edab1b92d48ff32
Reviewed-on: https://go-review.googlesource.com/c/164461
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
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 | 90 |
1 files changed, 30 insertions, 60 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteWasm.go b/src/cmd/compile/internal/ssa/rewriteWasm.go index c17ed54b3c..e14d6251be 100644 --- a/src/cmd/compile/internal/ssa/rewriteWasm.go +++ b/src/cmd/compile/internal/ssa/rewriteWasm.go @@ -6386,19 +6386,14 @@ func rewriteValueWasm_OpZeroExt16to32_0(v *Value) bool { } // match: (ZeroExt16to32 x) // cond: - // result: (I64ShrU (I64Shl x (I64Const [48])) (I64Const [48])) + // result: (I64And x (I64Const [0xffff])) for { x := v.Args[0] - v.reset(OpWasmI64ShrU) - v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) - v0.AddArg(x) - v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v1.AuxInt = 48 - v0.AddArg(v1) + v.reset(OpWasmI64And) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) + v0.AuxInt = 0xffff v.AddArg(v0) - v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v2.AuxInt = 48 - v.AddArg(v2) return true } } @@ -6423,19 +6418,14 @@ func rewriteValueWasm_OpZeroExt16to64_0(v *Value) bool { } // match: (ZeroExt16to64 x) // cond: - // result: (I64ShrU (I64Shl x (I64Const [48])) (I64Const [48])) + // result: (I64And x (I64Const [0xffff])) for { x := v.Args[0] - v.reset(OpWasmI64ShrU) - v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) - v0.AddArg(x) - v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v1.AuxInt = 48 - v0.AddArg(v1) + v.reset(OpWasmI64And) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) + v0.AuxInt = 0xffff v.AddArg(v0) - v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v2.AuxInt = 48 - v.AddArg(v2) return true } } @@ -6460,19 +6450,14 @@ func rewriteValueWasm_OpZeroExt32to64_0(v *Value) bool { } // match: (ZeroExt32to64 x) // cond: - // result: (I64ShrU (I64Shl x (I64Const [32])) (I64Const [32])) + // result: (I64And x (I64Const [0xffffffff])) for { x := v.Args[0] - v.reset(OpWasmI64ShrU) - v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) - v0.AddArg(x) - v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v1.AuxInt = 32 - v0.AddArg(v1) + v.reset(OpWasmI64And) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) + v0.AuxInt = 0xffffffff v.AddArg(v0) - v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v2.AuxInt = 32 - v.AddArg(v2) return true } } @@ -6497,19 +6482,14 @@ func rewriteValueWasm_OpZeroExt8to16_0(v *Value) bool { } // match: (ZeroExt8to16 x) // cond: - // result: (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56])) + // result: (I64And x (I64Const [0xff])) for { x := v.Args[0] - v.reset(OpWasmI64ShrU) - v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) - v0.AddArg(x) - v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v1.AuxInt = 56 - v0.AddArg(v1) + v.reset(OpWasmI64And) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) + v0.AuxInt = 0xff v.AddArg(v0) - v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v2.AuxInt = 56 - v.AddArg(v2) return true } } @@ -6534,19 +6514,14 @@ func rewriteValueWasm_OpZeroExt8to32_0(v *Value) bool { } // match: (ZeroExt8to32 x) // cond: - // result: (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56])) + // result: (I64And x (I64Const [0xff])) for { x := v.Args[0] - v.reset(OpWasmI64ShrU) - v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) - v0.AddArg(x) - v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v1.AuxInt = 56 - v0.AddArg(v1) + v.reset(OpWasmI64And) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) + v0.AuxInt = 0xff v.AddArg(v0) - v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v2.AuxInt = 56 - v.AddArg(v2) return true } } @@ -6571,19 +6546,14 @@ func rewriteValueWasm_OpZeroExt8to64_0(v *Value) bool { } // match: (ZeroExt8to64 x) // cond: - // result: (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56])) + // result: (I64And x (I64Const [0xff])) for { x := v.Args[0] - v.reset(OpWasmI64ShrU) - v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) - v0.AddArg(x) - v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v1.AuxInt = 56 - v0.AddArg(v1) + v.reset(OpWasmI64And) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) + v0.AuxInt = 0xff v.AddArg(v0) - v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) - v2.AuxInt = 56 - v.AddArg(v2) return true } } |