]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: optimize shift when counter has different type.
authorAlexandru Moșoi <brtzsnr@gmail.com>
Thu, 23 Mar 2017 21:29:59 +0000 (22:29 +0100)
committerAlexandru Moșoi <alexandru@mosoi.ro>
Fri, 24 Mar 2017 06:59:33 +0000 (06:59 +0000)
We already handle n << (uint64(c)&63).
This change also handles n << (uint8(c)&63)
where the SSA compiler promotes the counter to 32 bits.

Fixes #19681

Change-Id: I9327d64a994286aa0dbf76eb995578880be6923a
Reviewed-on: https://go-review.googlesource.com/38550
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 b8080910cfb79f17669b1e2d99c5b13f7fbb6ef6..2e3e6c01ba91b7404e7b7be183a0854a37eb62cb 100644 (file)
 
 (SHLL x (ANDLconst [31] y)) -> (SHLL x y)
 (SHLQ x (ANDQconst [63] y)) -> (SHLQ x y)
+(SHLQ x (ANDLconst [63] y)) -> (SHLQ x y)
 
 (SHRL x (ANDLconst [31] y)) -> (SHRL x y)
 (SHRQ x (ANDQconst [63] y)) -> (SHRQ x y)
+(SHRQ x (ANDLconst [63] y)) -> (SHRQ x y)
 
 // Rotate instructions
 
 (CMPLconst (SHRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) -> (FlagLT_ULT)
 (CMPQconst (SHRQconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 64 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT)
 (CMPQconst (ANDQconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT)
+(CMPQconst (ANDLconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT)
 (CMPLconst (ANDLconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT)
 (CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT)
 (CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT)
index 5143a88278c81c755093b36b4af2923092224ff2..e31d3b453a8324affa7a089b5021d21a1cdd026a 100644 (file)
@@ -2832,6 +2832,22 @@ func rewriteValueAMD64_OpAMD64CMPQconst(v *Value) bool {
                v.reset(OpAMD64FlagLT_ULT)
                return true
        }
+       // match: (CMPQconst (ANDLconst _ [m]) [n])
+       // cond: 0 <= m && m < n
+       // result: (FlagLT_ULT)
+       for {
+               n := v.AuxInt
+               v_0 := v.Args[0]
+               if v_0.Op != OpAMD64ANDLconst {
+                       break
+               }
+               m := v_0.AuxInt
+               if !(0 <= m && m < n) {
+                       break
+               }
+               v.reset(OpAMD64FlagLT_ULT)
+               return true
+       }
        // match: (CMPQconst (ANDQ x y) [0])
        // cond:
        // result: (TESTQ x y)
@@ -15680,6 +15696,24 @@ func rewriteValueAMD64_OpAMD64SHLQ(v *Value) bool {
                v.AddArg(y)
                return true
        }
+       // match: (SHLQ x (ANDLconst [63] y))
+       // cond:
+       // result: (SHLQ x y)
+       for {
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpAMD64ANDLconst {
+                       break
+               }
+               if v_1.AuxInt != 63 {
+                       break
+               }
+               y := v_1.Args[0]
+               v.reset(OpAMD64SHLQ)
+               v.AddArg(x)
+               v.AddArg(y)
+               return true
+       }
        return false
 }
 func rewriteValueAMD64_OpAMD64SHLQconst(v *Value) bool {
@@ -15901,6 +15935,24 @@ func rewriteValueAMD64_OpAMD64SHRQ(v *Value) bool {
                v.AddArg(y)
                return true
        }
+       // match: (SHRQ x (ANDLconst [63] y))
+       // cond:
+       // result: (SHRQ x y)
+       for {
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpAMD64ANDLconst {
+                       break
+               }
+               if v_1.AuxInt != 63 {
+                       break
+               }
+               y := v_1.Args[0]
+               v.reset(OpAMD64SHRQ)
+               v.AddArg(x)
+               v.AddArg(y)
+               return true
+       }
        return false
 }
 func rewriteValueAMD64_OpAMD64SHRQconst(v *Value) bool {