mirror of https://github.com/golang/go.git
cmd/compile: constant fold SHLxconst of a constant on amd64
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>
This commit is contained in:
parent
9c60094986
commit
f510cddcd1
|
|
@ -1482,6 +1482,9 @@
|
|||
(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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue