1
0
mirror of https://github.com/golang/go synced 2024-09-30 07:28:36 -06:00

cmd/compile: use shift boundedness when lowering shifts on 386

Minor improvements to generated code.

file                                          before   after    Δ       %
runtime.s                                     451117   450977   -140    -0.031%
compress/bzip2.s                              10202    10194    -8      -0.078%
compress/lzw.s                                5924     5904     -20     -0.338%
compress/flate.s                              45053    45032    -21     -0.047%
net.s                                         236980   236970   -10     -0.004%
vendor/golang.org/x/crypto/cryptobyte.s       29450    29439    -11     -0.037%
crypto/x509.s                                 107854   107840   -14     -0.013%
cmd/vendor/golang.org/x/arch/arm64/arm64asm.s 102448   102434   -14     -0.014%
cmd/internal/obj/arm.s                        60536    60528    -8      -0.013%
cmd/vendor/golang.org/x/mod/sumdb/tlog.s      38273    38276    +3      +0.008%
net/http.s                                    462215   462201   -14     -0.003%
cmd/compile/internal/ssa.s                    3951732  3954683  +2951   +0.075%
total                                         16946051 16948745 +2694   +0.016%

Change-Id: I9f6df1a90a295dce6fe86c8eb7576a8c96f8bb0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/217000
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Josh Bleecher Snyder 2020-01-23 21:47:42 -08:00
parent 333087623a
commit bcdd5d0024
2 changed files with 570 additions and 9 deletions

View File

@ -104,20 +104,32 @@
// Lowering shifts // Lowering shifts
// Unsigned shifts need to return 0 if shift amount is >= width of shifted value. // Unsigned shifts need to return 0 if shift amount is >= width of shifted value.
// result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff) // result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff)
(Lsh32x(32|16|8) <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) (Lsh32x(32|16|8) <t> x y) && !shiftIsBounded(v) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32])))
(Lsh16x(32|16|8) <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) (Lsh16x(32|16|8) <t> x y) && !shiftIsBounded(v) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32])))
(Lsh8x(32|16|8) <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) (Lsh8x(32|16|8) <t> x y) && !shiftIsBounded(v) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32])))
(Rsh32Ux(32|16|8) <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) (Lsh32x(32|16|8) <t> x y) && shiftIsBounded(v) -> (SHLL <t> x y)
(Rsh16Ux(32|16|8) <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [16]))) (Lsh16x(32|16|8) <t> x y) && shiftIsBounded(v) -> (SHLL <t> x y)
(Rsh8Ux(32|16|8) <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [8]))) (Lsh8x(32|16|8) <t> x y) && shiftIsBounded(v) -> (SHLL <t> x y)
(Rsh32Ux(32|16|8) <t> x y) && !shiftIsBounded(v) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32])))
(Rsh16Ux(32|16|8) <t> x y) && !shiftIsBounded(v) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [16])))
(Rsh8Ux(32|16|8) <t> x y) && !shiftIsBounded(v) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [8])))
(Rsh32Ux(32|16|8) <t> x y) && shiftIsBounded(v) -> (SHRL <t> x y)
(Rsh16Ux(32|16|8) <t> x y) && shiftIsBounded(v) -> (SHRW <t> x y)
(Rsh8Ux(32|16|8) <t> x y) && shiftIsBounded(v) -> (SHRB <t> x y)
// Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value. // Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value.
// We implement this by setting the shift value to -1 (all ones) if the shift value is >= width. // We implement this by setting the shift value to -1 (all ones) if the shift value is >= width.
(Rsh32x(32|16|8) <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [32]))))) (Rsh32x(32|16|8) <t> x y) && !shiftIsBounded(v) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [32])))))
(Rsh16x(32|16|8) <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [16]))))) (Rsh16x(32|16|8) <t> x y) && !shiftIsBounded(v) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [16])))))
(Rsh8x(32|16|8) <t> x y) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [8]))))) (Rsh8x(32|16|8) <t> x y) && !shiftIsBounded(v) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [8])))))
(Rsh32x(32|16|8) <t> x y) && shiftIsBounded(v) -> (SARL x y)
(Rsh16x(32|16|8) <t> x y) && shiftIsBounded(v) -> (SARW x y)
(Rsh8x(32|16|8) <t> x y) && shiftIsBounded(v) -> (SARB x y)
// constant shifts // constant shifts
// generic opt rewrites all constant shifts to shift by Const64 // generic opt rewrites all constant shifts to shift by Const64

File diff suppressed because it is too large Load Diff