mirror of
https://github.com/golang/go
synced 2024-11-18 20:04:52 -07:00
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 <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>
This commit is contained in:
parent
0f14c2a042
commit
7f8fda3c0b
@ -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])
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user