Commit 72d24a74 authored by Richard Musiol's avatar Richard Musiol Committed by Richard Musiol

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: default avatarCherry Zhang <cherryyz@google.com>
parent 1f17d610
...@@ -59,9 +59,9 @@ ...@@ -59,9 +59,9 @@
(SignExt32to64 x) -> (I64ShrS (I64Shl x (I64Const [32])) (I64Const [32])) (SignExt32to64 x) -> (I64ShrS (I64Shl x (I64Const [32])) (I64Const [32]))
(SignExt16to(64|32) x) -> (I64ShrS (I64Shl x (I64Const [48])) (I64Const [48])) (SignExt16to(64|32) x) -> (I64ShrS (I64Shl x (I64Const [48])) (I64Const [48]))
(SignExt8to(64|32|16) x) -> (I64ShrS (I64Shl x (I64Const [56])) (I64Const [56])) (SignExt8to(64|32|16) x) -> (I64ShrS (I64Shl x (I64Const [56])) (I64Const [56]))
(ZeroExt32to64 x) -> (I64ShrU (I64Shl x (I64Const [32])) (I64Const [32])) (ZeroExt32to64 x) -> (I64And x (I64Const [0xffffffff]))
(ZeroExt16to(64|32) x) -> (I64ShrU (I64Shl x (I64Const [48])) (I64Const [48])) (ZeroExt16to(64|32) x) -> (I64And x (I64Const [0xffff]))
(ZeroExt8to(64|32|16) x) -> (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56])) (ZeroExt8to(64|32|16) x) -> (I64And x (I64Const [0xff]))
(Slicemask x) -> (I64ShrS (I64Sub (I64Const [0]) x) (I64Const [63])) (Slicemask x) -> (I64ShrS (I64Sub (I64Const [0]) x) (I64Const [63]))
......
...@@ -6386,19 +6386,14 @@ func rewriteValueWasm_OpZeroExt16to32_0(v *Value) bool { ...@@ -6386,19 +6386,14 @@ func rewriteValueWasm_OpZeroExt16to32_0(v *Value) bool {
} }
// match: (ZeroExt16to32 x) // match: (ZeroExt16to32 x)
// cond: // cond:
// result: (I64ShrU (I64Shl x (I64Const [48])) (I64Const [48])) // result: (I64And x (I64Const [0xffff]))
for { for {
x := v.Args[0] x := v.Args[0]
v.reset(OpWasmI64ShrU) v.reset(OpWasmI64And)
v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) v.AddArg(x)
v0.AddArg(x) v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) v0.AuxInt = 0xffff
v1.AuxInt = 48
v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v2.AuxInt = 48
v.AddArg(v2)
return true return true
} }
} }
...@@ -6423,19 +6418,14 @@ func rewriteValueWasm_OpZeroExt16to64_0(v *Value) bool { ...@@ -6423,19 +6418,14 @@ func rewriteValueWasm_OpZeroExt16to64_0(v *Value) bool {
} }
// match: (ZeroExt16to64 x) // match: (ZeroExt16to64 x)
// cond: // cond:
// result: (I64ShrU (I64Shl x (I64Const [48])) (I64Const [48])) // result: (I64And x (I64Const [0xffff]))
for { for {
x := v.Args[0] x := v.Args[0]
v.reset(OpWasmI64ShrU) v.reset(OpWasmI64And)
v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) v.AddArg(x)
v0.AddArg(x) v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) v0.AuxInt = 0xffff
v1.AuxInt = 48
v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v2.AuxInt = 48
v.AddArg(v2)
return true return true
} }
} }
...@@ -6460,19 +6450,14 @@ func rewriteValueWasm_OpZeroExt32to64_0(v *Value) bool { ...@@ -6460,19 +6450,14 @@ func rewriteValueWasm_OpZeroExt32to64_0(v *Value) bool {
} }
// match: (ZeroExt32to64 x) // match: (ZeroExt32to64 x)
// cond: // cond:
// result: (I64ShrU (I64Shl x (I64Const [32])) (I64Const [32])) // result: (I64And x (I64Const [0xffffffff]))
for { for {
x := v.Args[0] x := v.Args[0]
v.reset(OpWasmI64ShrU) v.reset(OpWasmI64And)
v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) v.AddArg(x)
v0.AddArg(x) v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) v0.AuxInt = 0xffffffff
v1.AuxInt = 32
v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v2.AuxInt = 32
v.AddArg(v2)
return true return true
} }
} }
...@@ -6497,19 +6482,14 @@ func rewriteValueWasm_OpZeroExt8to16_0(v *Value) bool { ...@@ -6497,19 +6482,14 @@ func rewriteValueWasm_OpZeroExt8to16_0(v *Value) bool {
} }
// match: (ZeroExt8to16 x) // match: (ZeroExt8to16 x)
// cond: // cond:
// result: (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56])) // result: (I64And x (I64Const [0xff]))
for { for {
x := v.Args[0] x := v.Args[0]
v.reset(OpWasmI64ShrU) v.reset(OpWasmI64And)
v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) v.AddArg(x)
v0.AddArg(x) v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) v0.AuxInt = 0xff
v1.AuxInt = 56
v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v2.AuxInt = 56
v.AddArg(v2)
return true return true
} }
} }
...@@ -6534,19 +6514,14 @@ func rewriteValueWasm_OpZeroExt8to32_0(v *Value) bool { ...@@ -6534,19 +6514,14 @@ func rewriteValueWasm_OpZeroExt8to32_0(v *Value) bool {
} }
// match: (ZeroExt8to32 x) // match: (ZeroExt8to32 x)
// cond: // cond:
// result: (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56])) // result: (I64And x (I64Const [0xff]))
for { for {
x := v.Args[0] x := v.Args[0]
v.reset(OpWasmI64ShrU) v.reset(OpWasmI64And)
v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) v.AddArg(x)
v0.AddArg(x) v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) v0.AuxInt = 0xff
v1.AuxInt = 56
v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v2.AuxInt = 56
v.AddArg(v2)
return true return true
} }
} }
...@@ -6571,19 +6546,14 @@ func rewriteValueWasm_OpZeroExt8to64_0(v *Value) bool { ...@@ -6571,19 +6546,14 @@ func rewriteValueWasm_OpZeroExt8to64_0(v *Value) bool {
} }
// match: (ZeroExt8to64 x) // match: (ZeroExt8to64 x)
// cond: // cond:
// result: (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56])) // result: (I64And x (I64Const [0xff]))
for { for {
x := v.Args[0] x := v.Args[0]
v.reset(OpWasmI64ShrU) v.reset(OpWasmI64And)
v0 := b.NewValue0(v.Pos, OpWasmI64Shl, typ.Int64) v.AddArg(x)
v0.AddArg(x) v0 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v1 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64) v0.AuxInt = 0xff
v1.AuxInt = 56
v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := b.NewValue0(v.Pos, OpWasmI64Const, typ.Int64)
v2.AuxInt = 56
v.AddArg(v2)
return true return true
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment