]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify zero ext operations on wasm
authorRichard Musiol <mail@richard-musiol.de>
Thu, 28 Feb 2019 14:20:59 +0000 (15:20 +0100)
committerRichard Musiol <neelance@gmail.com>
Thu, 28 Feb 2019 15:25:42 +0000 (15:25 +0000)
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>
src/cmd/compile/internal/ssa/gen/Wasm.rules
src/cmd/compile/internal/ssa/rewriteWasm.go

index 64198839d0991c01589c11d2da9e33a3345c59c0..41d8d1122d1f3e321701e4b580ce5ff58081ed82 100644 (file)
@@ -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]))
 
index c17ed54b3c9528adc53c0ffbc968e6a78609ef24..e14d6251be9a1a7c95f0bebbf1f9bca816b112b1 100644 (file)
@@ -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
        }
 }