From b9ef4c0f5605efeb5e7e0a4ab817401d5e353b94 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sun, 16 Jun 2019 11:44:17 +0530 Subject: [PATCH] cmd/compile: coalesce a few shift rules for wasm Change-Id: I1b76daba90afd474390db8d9c238445abaac7ca6 Reviewed-on: https://go-review.googlesource.com/c/go/+/182557 Run-TryBot: Agniva De Sarker TryBot-Result: Gobot Gobot Reviewed-by: Richard Musiol Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/Wasm.rules | 48 ++++++--------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/Wasm.rules b/src/cmd/compile/internal/ssa/gen/Wasm.rules index 72bf01ba99f17..a8b7cf48a24e6 100644 --- a/src/cmd/compile/internal/ssa/gen/Wasm.rules +++ b/src/cmd/compile/internal/ssa/gen/Wasm.rules @@ -103,67 +103,43 @@ // Unsigned shifts need to return 0 if shift amount is >= width of shifted value. (Lsh64x64 x y) -> (Select (I64Shl x y) (I64Const [0]) (I64LtU y (I64Const [64]))) -(Lsh64x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y)) -(Lsh64x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y)) -(Lsh64x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y)) +(Lsh64x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y)) (Lsh32x64 x y) -> (Lsh64x64 x y) -(Lsh32x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y)) -(Lsh32x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y)) -(Lsh32x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y)) +(Lsh32x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y)) (Lsh16x64 x y) -> (Lsh64x64 x y) -(Lsh16x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y)) -(Lsh16x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y)) -(Lsh16x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y)) +(Lsh16x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y)) (Lsh8x64 x y) -> (Lsh64x64 x y) -(Lsh8x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y)) -(Lsh8x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y)) -(Lsh8x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y)) +(Lsh8x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y)) (Rsh64Ux64 x y) -> (Select (I64ShrU x y) (I64Const [0]) (I64LtU y (I64Const [64]))) -(Rsh64Ux32 x y) -> (Rsh64Ux64 x (ZeroExt32to64 y)) -(Rsh64Ux16 x y) -> (Rsh64Ux64 x (ZeroExt16to64 y)) -(Rsh64Ux8 x y) -> (Rsh64Ux64 x (ZeroExt8to64 y)) +(Rsh64Ux(32|16|8) x y) -> (Rsh64Ux64 x (ZeroExt(32|16|8)to64 y)) (Rsh32Ux64 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) y) -(Rsh32Ux32 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt32to64 y)) -(Rsh32Ux16 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt16to64 y)) -(Rsh32Ux8 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt8to64 y)) +(Rsh32Ux(32|16|8) x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt(32|16|8)to64 y)) (Rsh16Ux64 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) y) -(Rsh16Ux32 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt32to64 y)) -(Rsh16Ux16 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt16to64 y)) -(Rsh16Ux8 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt8to64 y)) +(Rsh16Ux(32|16|8) x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt(32|16|8)to64 y)) (Rsh8Ux64 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) y) -(Rsh8Ux32 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt32to64 y)) -(Rsh8Ux16 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt16to64 y)) -(Rsh8Ux8 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt8to64 y)) +(Rsh8Ux(32|16|8) x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt(32|16|8)to64 y)) // Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value. // We implement this by setting the shift value to (width - 1) if the shift value is >= width. (Rsh64x64 x y) -> (I64ShrS x (Select y (I64Const [63]) (I64LtU y (I64Const [64])))) -(Rsh64x32 x y) -> (Rsh64x64 x (ZeroExt32to64 y)) -(Rsh64x16 x y) -> (Rsh64x64 x (ZeroExt16to64 y)) -(Rsh64x8 x y) -> (Rsh64x64 x (ZeroExt8to64 y)) +(Rsh64x(32|16|8) x y) -> (Rsh64x64 x (ZeroExt(32|16|8)to64 y)) (Rsh32x64 x y) -> (Rsh64x64 (SignExt32to64 x) y) -(Rsh32x32 x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt32to64 y)) -(Rsh32x16 x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt16to64 y)) -(Rsh32x8 x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt8to64 y)) +(Rsh32x(32|16|8) x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt(32|16|8)to64 y)) (Rsh16x64 x y) -> (Rsh64x64 (SignExt16to64 x) y) -(Rsh16x32 x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt32to64 y)) -(Rsh16x16 x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt16to64 y)) -(Rsh16x8 x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt8to64 y)) +(Rsh16x(32|16|8) x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt(32|16|8)to64 y)) (Rsh8x64 x y) -> (Rsh64x64 (SignExt8to64 x) y) -(Rsh8x32 x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt32to64 y)) -(Rsh8x16 x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt16to64 y)) -(Rsh8x8 x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt8to64 y)) +(Rsh8x(32|16|8) x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt(32|16|8)to64 y)) // Lowering rotates (RotateLeft8 x (I64Const [c])) -> (Or8 (Lsh8x64 x (I64Const [c&7])) (Rsh8Ux64 x (I64Const [-c&7])))