]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use proper magnitude for (x>>c) & uppermask = 0
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 20 Apr 2020 20:47:02 +0000 (03:47 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 21 Apr 2020 03:45:26 +0000 (03:45 +0000)
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 <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index edd8259de353e6827160e25f7dd8cd27a576a4b4..899e3e6752b1ef2acdb3bf871c55abe3e931466b 100644 (file)
 
 // (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])
index 214de6448d55658a98ad42bcfe5a320e1753ad4b..6d42f3a36c8d3cd7fb3a8655731ba79850906a73 100644 (file)
@@ -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)