mirror of
https://github.com/golang/go
synced 2024-11-27 01:21:18 -07:00
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>
This commit is contained in:
parent
1f17d61026
commit
72d24a7484
@ -59,9 +59,9 @@
|
||||
(SignExt32to64 x) -> (I64ShrS (I64Shl x (I64Const [32])) (I64Const [32]))
|
||||
(SignExt16to(64|32) x) -> (I64ShrS (I64Shl x (I64Const [48])) (I64Const [48]))
|
||||
(SignExt8to(64|32|16) x) -> (I64ShrS (I64Shl x (I64Const [56])) (I64Const [56]))
|
||||
(ZeroExt32to64 x) -> (I64ShrU (I64Shl x (I64Const [32])) (I64Const [32]))
|
||||
(ZeroExt16to(64|32) x) -> (I64ShrU (I64Shl x (I64Const [48])) (I64Const [48]))
|
||||
(ZeroExt8to(64|32|16) x) -> (I64ShrU (I64Shl x (I64Const [56])) (I64Const [56]))
|
||||
(ZeroExt32to64 x) -> (I64And x (I64Const [0xffffffff]))
|
||||
(ZeroExt16to(64|32) x) -> (I64And x (I64Const [0xffff]))
|
||||
(ZeroExt8to(64|32|16) x) -> (I64And x (I64Const [0xff]))
|
||||
|
||||
(Slicemask x) -> (I64ShrS (I64Sub (I64Const [0]) x) (I64Const [63]))
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user