Commit d8ee180a authored by Alexandru Moșoi's avatar Alexandru Moșoi Committed by Alexandru Moșoi

cmd/compile: fold more of CMPQ and ANDQ

g used to produce CMPQ/SBBQ/ANDQ, but f didn't even though
s&15 is at most s&63.

func f(x uint64, s uint) uint64 {
        return x >> (s & 63)
}
func g(x uint64, s uint) uint64 {
        return x >> (s & 15)
}

Change-Id: Iab4a1a6e10b471dead9f1203e9d894677cf07bb2
Reviewed-on: https://go-review.googlesource.com/21048
Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent df2b2eb6
......@@ -942,10 +942,10 @@
(CMPBconst (MOVBconst [x]) [y]) && int8(x)>int8(y) && uint8(x)>uint8(y) -> (FlagGT_UGT)
// Other known comparisons.
(CMPQconst (ANDQconst _ [m]) [n]) && m+1==n && isPowerOfTwo(n) -> (FlagLT_ULT)
(CMPLconst (ANDLconst _ [m]) [n]) && int32(m)+1==int32(n) && isPowerOfTwo(int64(int32(n))) -> (FlagLT_ULT)
(CMPWconst (ANDWconst _ [m]) [n]) && int16(m)+1==int16(n) && isPowerOfTwo(int64(int16(n))) -> (FlagLT_ULT)
(CMPBconst (ANDBconst _ [m]) [n]) && int8(m)+1==int8(n) && isPowerOfTwo(int64(int8(n))) -> (FlagLT_ULT)
(CMPQconst (ANDQconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT)
(CMPLconst (ANDLconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT)
(CMPWconst (ANDWconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT)
(CMPBconst (ANDBconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT)
// TODO: DIVxU also.
// Absorb flag constants into SBB ops.
......
......@@ -2240,7 +2240,7 @@ func rewriteValueAMD64_OpAMD64CMPBconst(v *Value, config *Config) bool {
return true
}
// match: (CMPBconst (ANDBconst _ [m]) [n])
// cond: int8(m)+1==int8(n) && isPowerOfTwo(int64(int8(n)))
// cond: 0 <= int8(m) && int8(m) < int8(n)
// result: (FlagLT_ULT)
for {
v_0 := v.Args[0]
......@@ -2249,7 +2249,7 @@ func rewriteValueAMD64_OpAMD64CMPBconst(v *Value, config *Config) bool {
}
m := v_0.AuxInt
n := v.AuxInt
if !(int8(m)+1 == int8(n) && isPowerOfTwo(int64(int8(n)))) {
if !(0 <= int8(m) && int8(m) < int8(n)) {
break
}
v.reset(OpAMD64FlagLT_ULT)
......@@ -2414,7 +2414,7 @@ func rewriteValueAMD64_OpAMD64CMPLconst(v *Value, config *Config) bool {
return true
}
// match: (CMPLconst (ANDLconst _ [m]) [n])
// cond: int32(m)+1==int32(n) && isPowerOfTwo(int64(int32(n)))
// cond: 0 <= int32(m) && int32(m) < int32(n)
// result: (FlagLT_ULT)
for {
v_0 := v.Args[0]
......@@ -2423,7 +2423,7 @@ func rewriteValueAMD64_OpAMD64CMPLconst(v *Value, config *Config) bool {
}
m := v_0.AuxInt
n := v.AuxInt
if !(int32(m)+1 == int32(n) && isPowerOfTwo(int64(int32(n)))) {
if !(0 <= int32(m) && int32(m) < int32(n)) {
break
}
v.reset(OpAMD64FlagLT_ULT)
......@@ -2594,7 +2594,7 @@ func rewriteValueAMD64_OpAMD64CMPQconst(v *Value, config *Config) bool {
return true
}
// match: (CMPQconst (ANDQconst _ [m]) [n])
// cond: m+1==n && isPowerOfTwo(n)
// cond: 0 <= m && m < n
// result: (FlagLT_ULT)
for {
v_0 := v.Args[0]
......@@ -2603,7 +2603,7 @@ func rewriteValueAMD64_OpAMD64CMPQconst(v *Value, config *Config) bool {
}
m := v_0.AuxInt
n := v.AuxInt
if !(m+1 == n && isPowerOfTwo(n)) {
if !(0 <= m && m < n) {
break
}
v.reset(OpAMD64FlagLT_ULT)
......@@ -2768,7 +2768,7 @@ func rewriteValueAMD64_OpAMD64CMPWconst(v *Value, config *Config) bool {
return true
}
// match: (CMPWconst (ANDWconst _ [m]) [n])
// cond: int16(m)+1==int16(n) && isPowerOfTwo(int64(int16(n)))
// cond: 0 <= int16(m) && int16(m) < int16(n)
// result: (FlagLT_ULT)
for {
v_0 := v.Args[0]
......@@ -2777,7 +2777,7 @@ func rewriteValueAMD64_OpAMD64CMPWconst(v *Value, config *Config) bool {
}
m := v_0.AuxInt
n := v.AuxInt
if !(int16(m)+1 == int16(n) && isPowerOfTwo(int64(int16(n)))) {
if !(0 <= int16(m) && int16(m) < int16(n)) {
break
}
v.reset(OpAMD64FlagLT_ULT)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment