mirror of
https://github.com/golang/go
synced 2024-11-17 03:04:44 -07:00
e37cc29863
This CL incorporates code from CL 201206 by Josh Bleecher Snyder (thanks Josh). This CL restores the integer-in-range optimizations in the SSA backend. The fuse pass is enhanced to detect inequalities that could be merged and fuse their associated blocks while the generic rules optimize them into a single unsigned comparison. For example, the inequality `x >= 0 && x < 10` will now be optimized to `unsigned(x) < 10`. Overall has a fairly positive impact on binary sizes. name old time/op new time/op delta Template 192ms ± 1% 192ms ± 1% ~ (p=0.757 n=17+18) Unicode 76.6ms ± 2% 76.5ms ± 2% ~ (p=0.603 n=19+19) GoTypes 694ms ± 1% 693ms ± 1% ~ (p=0.569 n=19+20) Compiler 3.26s ± 0% 3.27s ± 0% +0.25% (p=0.000 n=20+20) SSA 7.41s ± 0% 7.49s ± 0% +1.10% (p=0.000 n=17+19) Flate 120ms ± 1% 120ms ± 1% +0.38% (p=0.003 n=19+19) GoParser 152ms ± 1% 152ms ± 1% ~ (p=0.061 n=17+19) Reflect 422ms ± 1% 425ms ± 2% +0.76% (p=0.001 n=18+20) Tar 167ms ± 1% 167ms ± 0% ~ (p=0.730 n=18+19) XML 233ms ± 4% 231ms ± 1% ~ (p=0.752 n=20+17) LinkCompiler 927ms ± 8% 928ms ± 8% ~ (p=0.857 n=19+20) ExternalLinkCompiler 1.81s ± 2% 1.81s ± 2% ~ (p=0.513 n=19+20) LinkWithoutDebugCompiler 556ms ±10% 583ms ±13% +4.95% (p=0.007 n=20+20) [Geo mean] 478ms 481ms +0.52% name old user-time/op new user-time/op delta Template 270ms ± 5% 269ms ± 7% ~ (p=0.925 n=20+20) Unicode 134ms ± 7% 131ms ±14% ~ (p=0.593 n=18+20) GoTypes 981ms ± 3% 987ms ± 2% +0.63% (p=0.049 n=19+18) Compiler 4.50s ± 2% 4.50s ± 1% ~ (p=0.588 n=19+20) SSA 10.6s ± 2% 10.6s ± 1% ~ (p=0.141 n=20+19) Flate 164ms ± 8% 165ms ±10% ~ (p=0.738 n=20+20) GoParser 202ms ± 5% 203ms ± 6% ~ (p=0.820 n=20+20) Reflect 587ms ± 6% 597ms ± 3% ~ (p=0.087 n=20+18) Tar 230ms ± 6% 228ms ± 8% ~ (p=0.569 n=19+20) XML 311ms ± 6% 314ms ± 5% ~ (p=0.369 n=20+20) LinkCompiler 878ms ± 8% 887ms ± 7% ~ (p=0.289 n=20+20) ExternalLinkCompiler 1.60s ± 7% 1.60s ± 7% ~ (p=0.820 n=20+20) LinkWithoutDebugCompiler 498ms ±12% 489ms ±11% ~ (p=0.398 n=20+20) [Geo mean] 611ms 611ms +0.05% name old alloc/op new alloc/op delta Template 36.1MB ± 0% 36.0MB ± 0% -0.32% (p=0.000 n=20+20) Unicode 28.3MB ± 0% 28.3MB ± 0% -0.03% (p=0.000 n=19+20) GoTypes 121MB ± 0% 121MB ± 0% ~ (p=0.226 n=16+20) Compiler 563MB ± 0% 563MB ± 0% ~ (p=0.166 n=20+19) SSA 1.32GB ± 0% 1.33GB ± 0% +0.88% (p=0.000 n=20+19) Flate 22.7MB ± 0% 22.7MB ± 0% -0.02% (p=0.033 n=19+20) GoParser 27.9MB ± 0% 27.9MB ± 0% -0.02% (p=0.001 n=20+20) Reflect 78.3MB ± 0% 78.2MB ± 0% -0.01% (p=0.019 n=20+20) Tar 34.0MB ± 0% 34.0MB ± 0% -0.04% (p=0.000 n=20+20) XML 43.9MB ± 0% 43.9MB ± 0% -0.07% (p=0.000 n=20+19) LinkCompiler 205MB ± 0% 205MB ± 0% +0.44% (p=0.000 n=20+18) ExternalLinkCompiler 223MB ± 0% 223MB ± 0% +0.03% (p=0.000 n=20+20) LinkWithoutDebugCompiler 139MB ± 0% 142MB ± 0% +1.75% (p=0.000 n=20+20) [Geo mean] 93.7MB 93.9MB +0.20% name old allocs/op new allocs/op delta Template 363k ± 0% 361k ± 0% -0.58% (p=0.000 n=20+19) Unicode 329k ± 0% 329k ± 0% -0.06% (p=0.000 n=19+20) GoTypes 1.28M ± 0% 1.28M ± 0% -0.01% (p=0.000 n=20+20) Compiler 5.40M ± 0% 5.40M ± 0% -0.01% (p=0.000 n=20+20) SSA 12.7M ± 0% 12.8M ± 0% +0.80% (p=0.000 n=20+20) Flate 228k ± 0% 228k ± 0% ~ (p=0.194 n=20+20) GoParser 295k ± 0% 295k ± 0% -0.04% (p=0.000 n=20+20) Reflect 949k ± 0% 949k ± 0% -0.01% (p=0.000 n=20+20) Tar 337k ± 0% 337k ± 0% -0.06% (p=0.000 n=20+20) XML 418k ± 0% 417k ± 0% -0.17% (p=0.000 n=20+20) LinkCompiler 553k ± 0% 554k ± 0% +0.22% (p=0.000 n=20+19) ExternalLinkCompiler 1.52M ± 0% 1.52M ± 0% +0.27% (p=0.000 n=20+20) LinkWithoutDebugCompiler 186k ± 0% 186k ± 0% +0.06% (p=0.000 n=20+20) [Geo mean] 723k 723k +0.03% name old text-bytes new text-bytes delta HelloSize 828kB ± 0% 828kB ± 0% -0.01% (p=0.000 n=20+20) name old data-bytes new data-bytes delta HelloSize 13.4kB ± 0% 13.4kB ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 180kB ± 0% 180kB ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 1.23MB ± 0% 1.23MB ± 0% -0.33% (p=0.000 n=20+20) file before after Δ % addr2line 4320075 4311883 -8192 -0.190% asm 5191932 5187836 -4096 -0.079% buildid 2835338 2831242 -4096 -0.144% compile 20531717 20569099 +37382 +0.182% cover 5322511 5318415 -4096 -0.077% dist 3723749 3719653 -4096 -0.110% doc 4743515 4739419 -4096 -0.086% fix 3413960 3409864 -4096 -0.120% link 6690119 6686023 -4096 -0.061% nm 4269616 4265520 -4096 -0.096% pprof 14942189 14929901 -12288 -0.082% trace 11807164 11790780 -16384 -0.139% vet 8384104 8388200 +4096 +0.049% go 15339076 15334980 -4096 -0.027% total 132258257 132226007 -32250 -0.024% Fixes #30645. Change-Id: If551ac5996097f3685870d083151b5843170aab0 Reviewed-on: https://go-review.googlesource.com/c/go/+/165998 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> |
||
---|---|---|
.. | ||
addrcalc.go | ||
alloc.go | ||
arithmetic.go | ||
bitfield.go | ||
bits.go | ||
compare_and_branch.go | ||
comparisons.go | ||
condmove.go | ||
copy.go | ||
floats.go | ||
fuse.go | ||
issue22703.go | ||
issue25378.go | ||
issue31618.go | ||
issue33580.go | ||
mapaccess.go | ||
maps.go | ||
math.go | ||
mathbits.go | ||
memcombine.go | ||
memops.go | ||
noextend.go | ||
race.go | ||
README | ||
rotate.go | ||
shift.go | ||
slices.go | ||
stack.go | ||
strings.go | ||
structs.go | ||
switch.go | ||
zerosize.go |
// Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. The codegen directory contains code generation tests for the gc compiler. - Introduction The test harness compiles Go code inside files in this directory and matches the generated assembly (the output of `go tool compile -S`) against a set of regexps to be specified in comments that follow a special syntax (described below). The test driver is implemented as a step of the top-level test/run.go suite, called "asmcheck". The codegen harness is part of the all.bash test suite, but for performance reasons only the codegen tests for the host machine's GOARCH are enabled by default. To perform comprehensive tests for all the supported architectures, one can run the following command $ ../bin/go run run.go -all_codegen -v codegen in the top-level test directory. This is recommended after any change that affect the compiler's code. The test harness compiles the tests with the same go toolchain that is used to run run.go. After writing tests for a newly added codegen transformation, it can be useful to first run the test harness with a toolchain from a released Go version (and verify that the new tests fail), and then re-runnig the tests using the devel toolchain. - Regexps comments syntax Instructions to match are specified inside plain comments that start with an architecture tag, followed by a colon and a quoted Go-style regexp to be matched. For example, the following test: func Sqrt(x float64) float64 { // amd64:"SQRTSD" // arm64:"FSQRTD" return math.Sqrt(x) } verifies that math.Sqrt calls are intrinsified to a SQRTSD instruction on amd64, and to a FSQRTD instruction on arm64. It is possible to put multiple architectures checks into the same line, as: // amd64:"SQRTSD" arm64:"FSQRTD" although this form should be avoided when doing so would make the regexps line excessively long and difficult to read. Comments that are on their own line will be matched against the first subsequent non-comment line. Inline comments are also supported; the regexp will be matched against the code found on the same line: func Sqrt(x float64) float64 { return math.Sqrt(x) // arm:"SQRTD" } It's possible to specify a comma-separated list of regexps to be matched. For example, the following test: func TZ8(n uint8) int { // amd64:"BSFQ","ORQ\t\\$256" return bits.TrailingZeros8(n) } verifies that the code generated for a bits.TrailingZeros8 call on amd64 contains both a "BSFQ" instruction and an "ORQ $256". Note how the ORQ regex includes a tab char (\t). In the Go assembly syntax, operands are separated from opcodes by a tabulation. Regexps can be quoted using either " or `. Special characters must be escaped accordingly. Both of these are accepted, and equivalent: // amd64:"ADDQ\t\\$3" // amd64:`ADDQ\t\$3` and they'll match this assembly line: ADDQ $3 Negative matches can be specified using a - before the quoted regexp. For example: func MoveSmall() { x := [...]byte{1, 2, 3, 4, 5, 6, 7} copy(x[1:], x[:]) // arm64:-".*memmove" } verifies that NO memmove call is present in the assembly generated for the copy() line. - Architecture specifiers There are three different ways to specify on which architecture a test should be run: * Specify only the architecture (eg: "amd64"). This indicates that the check should be run on all the supported architecture variants. For instance, arm checks will be run against all supported GOARM variations (5,6,7). * Specify both the architecture and a variant, separated by a slash (eg: "arm/7"). This means that the check will be run only on that specific variant. * Specify the operating system, the architecture and the variant, separated by slashes (eg: "plan9/386/sse2", "plan9/amd64/"). This is needed in the rare case that you need to do a codegen test affected by a specific operating system; by default, tests are compiled only targeting linux. - Remarks, and Caveats -- Write small test functions As a general guideline, test functions should be small, to avoid possible interactions between unrelated lines of code that may be introduced, for example, by the compiler's optimization passes. Any given line of Go code could get assigned more instructions that it may appear from reading the source. In particular, matching all MOV instructions should be avoided; the compiler may add them for unrelated reasons and this may render the test ineffective. -- Line matching logic Regexps are always matched from the start of the instructions line. This means, for example, that the "MULQ" regexp is equivalent to "^MULQ" (^ representing the start of the line), and it will NOT match the following assembly line: IMULQ $99, AX To force a match at any point of the line, ".*MULQ" should be used. For the same reason, a negative regexp like -"memmove" is not enough to make sure that no memmove call is included in the assembly. A memmove call looks like this: CALL runtime.memmove(SB) To make sure that the "memmove" symbol does not appear anywhere in the assembly, the negative regexp to be used is -".*memmove".