]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: constant fold SHLxconst of a constant on amd64
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 23 Feb 2020 05:47:49 +0000 (21:47 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 26 Feb 2020 18:43:30 +0000 (18:43 +0000)
These rules fire in particular when comparing to a constant
string of length two. They should trigger even more after CL 220499.

file    before    after     Δ       %
compile 20639976  20635880  -4096   -0.020%
total   116003456 115999360 -4096   -0.004%

Change-Id: I21c1c02cf32d710d7a4eb12efab00f02796ccb84
Reviewed-on: https://go-review.googlesource.com/c/go/+/220694
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
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 25b618d82ee3374f310a8502c281c39be86c51de..0b8115249efae1cba0253f243c07b3323a959c94 100644 (file)
 (XORQ x x) -> (MOVQconst [0])
 (XORL x x) -> (MOVLconst [0])
 
+(SHLLconst [d] (MOVLconst [c])) -> (MOVLconst [int64(int32(c)) << uint64(d)])
+(SHLQconst [d] (MOVQconst [c])) -> (MOVQconst [c << uint64(d)])
+
 // Fold NEG into ADDconst/MULconst. Take care to keep c in 32 bit range.
 (NEGQ (ADDQconst [c] (NEGQ x))) && c != -(1<<31) -> (ADDQconst [-c] x)
 (MULQconst [c] (NEGQ x)) && c != -(1<<31) -> (MULQconst [-c] x)
index 7cbac3cb1c5bffd89ef642aeca7da62f576f2bf8..0a2669e124e7bb7cd1d25bce858635231495b678 100644 (file)
@@ -31354,6 +31354,18 @@ func rewriteValueAMD64_OpAMD64SHLLconst(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (SHLLconst [d] (MOVLconst [c]))
+       // result: (MOVLconst [int64(int32(c)) << uint64(d)])
+       for {
+               d := v.AuxInt
+               if v_0.Op != OpAMD64MOVLconst {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpAMD64MOVLconst)
+               v.AuxInt = int64(int32(c)) << uint64(d)
+               return true
+       }
        return false
 }
 func rewriteValueAMD64_OpAMD64SHLQ(v *Value) bool {
@@ -31586,6 +31598,18 @@ func rewriteValueAMD64_OpAMD64SHLQconst(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (SHLQconst [d] (MOVQconst [c]))
+       // result: (MOVQconst [c << uint64(d)])
+       for {
+               d := v.AuxInt
+               if v_0.Op != OpAMD64MOVQconst {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpAMD64MOVQconst)
+               v.AuxInt = c << uint64(d)
+               return true
+       }
        return false
 }
 func rewriteValueAMD64_OpAMD64SHRB(v *Value) bool {