]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fold more of CMPQ and ANDQ
authorAlexandru Moșoi <brtzsnr@gmail.com>
Thu, 24 Mar 2016 07:48:41 +0000 (08:48 +0100)
committerAlexandru Moșoi <alexandru@mosoi.ro>
Thu, 24 Mar 2016 19:38:21 +0000 (19:38 +0000)
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: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go

index e564f6ff66ed047af81531ace87bce5382e513b3..53e765802dd13cf366dcbc290f1f314b86f8b7a5 100644 (file)
 (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.
index 175e9624c755cf8a8e112b84491daa541784c9e8..2cb35a186230322f6b0b76a774631d9037a5402c 100644 (file)
@@ -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)