0
1
mirror of https://github.com/golang/go synced 2025-06-12 17:11:51 +00:00

cmd/compile: add rules to eliminate unnecessary signed shifts

This change to the rules removes some unnecessary signed shifts
that appear in the math/rand functions. Existing rules did not
cover some of the signed cases.

A little improvement seen in math/rand due to removing 1 of 2
instructions generated for Int31n, which is inlined quite a bit.

Intn1000                 46.9ns ± 0%  45.5ns ± 0%   -2.99%  (p=1.000 n=1+1)
Int63n1000               33.5ns ± 0%  32.8ns ± 0%   -2.09%  (p=1.000 n=1+1)
Int31n1000               32.7ns ± 0%  32.6ns ± 0%   -0.31%  (p=1.000 n=1+1)
Float32                  32.7ns ± 0%  30.3ns ± 0%   -7.34%  (p=1.000 n=1+1)
Float64                  21.7ns ± 0%  20.9ns ± 0%   -3.69%  (p=1.000 n=1+1)
Perm3                     205ns ± 0%   202ns ± 0%   -1.46%  (p=1.000 n=1+1)
Perm30                   1.71µs ± 0%  1.68µs ± 0%   -1.35%  (p=1.000 n=1+1)
Perm30ViaShuffle         1.65µs ± 0%  1.65µs ± 0%   -0.30%  (p=1.000 n=1+1)
ShuffleOverhead          2.83µs ± 0%  2.83µs ± 0%   -0.07%  (p=1.000 n=1+1)
Read3                    18.7ns ± 0%  16.1ns ± 0%  -13.90%  (p=1.000 n=1+1)
Read64                    126ns ± 0%   124ns ± 0%   -1.59%  (p=1.000 n=1+1)
Read1000                 1.75µs ± 0%  1.63µs ± 0%   -7.08%  (p=1.000 n=1+1)

Change-Id: I11502dfca7d65aafc76749a8d713e9e50c24a858
Reviewed-on: https://go-review.googlesource.com/c/go/+/225917
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Lynn Boger
2020-03-26 16:01:40 -04:00
parent 3840aced14
commit e4a1cf8a56
3 changed files with 113 additions and 0 deletions
src/cmd/compile/internal/ssa
test/codegen

@ -125,3 +125,26 @@ func lshGuarded64(v int64, s uint) int64 {
}
panic("shift too large")
}
func checkWidenAfterShift(v int64, u uint64) (int64, uint64) {
// ppc64le:-".*MOVW"
f := int32(v>>32)
// ppc64le:".*MOVW"
f += int32(v>>31)
// ppc64le:-".*MOVH"
g := int16(v>>48)
// ppc64le:".*MOVH"
g += int16(v>>30)
// ppc64le:-".*MOVH"
g += int16(f>>16)
// ppc64le:-".*MOVB"
h := int8(v>>56)
// ppc64le:".*MOVB"
h += int8(v>>28)
// ppc64le:-".*MOVB"
h += int8(f>>24)
// ppc64le:".*MOVB"
h += int8(f>>16)
return int64(h),uint64(g)
}