From 7f8fda3c0bfcc832934aa75b4580b4c780e1cb52 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 21 Apr 2020 03:47:02 +0700 Subject: [PATCH] cmd/compile: use proper magnitude for (x>>c) & uppermask = 0 This is followup of CL 228860, which rewrite shift rules to use typed aux. That CL introduced nlz* functions, to refactor left shift rules. While at it, we realize there's a bug in old rules with both right/left shift rules, but only fix for left shift rules only. This CL fixes the bug for right shift rules. Passes toolstash-check. Change-Id: Id8f2158b1b66c9e87f3fdeaa7ae3e35dc0666f8b Reviewed-on: https://go-review.googlesource.com/c/go/+/229137 Run-TryBot: Cuong Manh Le TryBot-Result: Gobot Gobot Reviewed-by: Emmanuel Odeke Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/generic.rules | 6 +++--- src/cmd/compile/internal/ssa/rewritegeneric.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index edd8259de35..899e3e6752b 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -448,9 +448,9 @@ // (x >> c) & uppermask = 0 (And64 (Const64 [m]) (Rsh64Ux64 _ (Const64 [c]))) && c >= int64(64-ntz64(m)) => (Const64 [0]) -(And32 (Const32 [m]) (Rsh32Ux64 _ (Const64 [c]))) && c >= int64(64-ntz32(m)) => (Const32 [0]) -(And16 (Const16 [m]) (Rsh16Ux64 _ (Const64 [c]))) && c >= int64(64-ntz16(m)) => (Const16 [0]) -(And8 (Const8 [m]) (Rsh8Ux64 _ (Const64 [c]))) && c >= int64(64-ntz8(m)) => (Const8 [0]) +(And32 (Const32 [m]) (Rsh32Ux64 _ (Const64 [c]))) && c >= int64(32-ntz32(m)) => (Const32 [0]) +(And16 (Const16 [m]) (Rsh16Ux64 _ (Const64 [c]))) && c >= int64(16-ntz16(m)) => (Const16 [0]) +(And8 (Const8 [m]) (Rsh8Ux64 _ (Const64 [c]))) && c >= int64(8-ntz8(m)) => (Const8 [0]) // (x << c) & lowermask = 0 (And64 (Const64 [m]) (Lsh64x64 _ (Const64 [c]))) && c >= int64(64-nlz64(m)) => (Const64 [0]) diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 214de6448d5..6d42f3a36c8 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -1571,7 +1571,7 @@ func rewriteValuegeneric_OpAnd16(v *Value) bool { break } // match: (And16 (Const16 [m]) (Rsh16Ux64 _ (Const64 [c]))) - // cond: c >= int64(64-ntz16(m)) + // cond: c >= int64(16-ntz16(m)) // result: (Const16 [0]) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -1588,7 +1588,7 @@ func rewriteValuegeneric_OpAnd16(v *Value) bool { continue } c := auxIntToInt64(v_1_1.AuxInt) - if !(c >= int64(64-ntz16(m))) { + if !(c >= int64(16-ntz16(m))) { continue } v.reset(OpConst16) @@ -1769,7 +1769,7 @@ func rewriteValuegeneric_OpAnd32(v *Value) bool { break } // match: (And32 (Const32 [m]) (Rsh32Ux64 _ (Const64 [c]))) - // cond: c >= int64(64-ntz32(m)) + // cond: c >= int64(32-ntz32(m)) // result: (Const32 [0]) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -1786,7 +1786,7 @@ func rewriteValuegeneric_OpAnd32(v *Value) bool { continue } c := auxIntToInt64(v_1_1.AuxInt) - if !(c >= int64(64-ntz32(m))) { + if !(c >= int64(32-ntz32(m))) { continue } v.reset(OpConst32) @@ -2165,7 +2165,7 @@ func rewriteValuegeneric_OpAnd8(v *Value) bool { break } // match: (And8 (Const8 [m]) (Rsh8Ux64 _ (Const64 [c]))) - // cond: c >= int64(64-ntz8(m)) + // cond: c >= int64(8-ntz8(m)) // result: (Const8 [0]) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -2182,7 +2182,7 @@ func rewriteValuegeneric_OpAnd8(v *Value) bool { continue } c := auxIntToInt64(v_1_1.AuxInt) - if !(c >= int64(64-ntz8(m))) { + if !(c >= int64(8-ntz8(m))) { continue } v.reset(OpConst8)