ba6bd967d2
The current phiopt pass just transforms the following code
x := false
if b { x = true}
into
x = b
But we find code in runtime.atoi like this:
neg := false
if s[0] == '-' {
neg = true
s = s[1:]
}
The current phiopt pass does not covert it into code like:
neg := s[0] == '-'
if neg { s = s[1:] }
Therefore, this patch strengthens the phiopt pass so that the
boolean Phi value "neg" can be replaced with a copy of control
value "s[0] == '-'", thereby using "cmp+cset" instead of a branch.
But in some cases even replacing the boolean Phis cannot eliminate
this branch. In the following case, this patch replaces "d" with a
copy of "a<0", but the regalloc pass will insert the "Load {c}"
value into an empty block to split the live ranges, which causes
the branch to not be eliminated.
For example:
func test(a, b, c int) (bool, int) {
d := false
if (a<0) {
if (b<0) {
c = c+1
}
d = true
}
return d, c
}
The optimized assembly code:
MOVD "".a(FP), R0
TBZ $63, R0, 48
MOVD "".c+16(FP), R1
ADD $1, R1, R2
MOVD "".b+8(FP), R3
CMP ZR, R3
CSEL LT, R2, R1, R1
CMP ZR, R0
CSET LT, R0
MOVB R0, "".~r3+24(FP)
MOVD R1, "".~r4+32(FP)
RET (R30)
MOVD "".c+16(FP), R1
JMP 28
The benchmark:
name old time/op new time/op delta
pkg:cmd/compile/internal/ssa goos:linux goarch:arm64
PhioptPass 117783.250000ns +- 1% 117219.111111ns +- 1% ~ (p=0.074 n=8+9)
Statistical data from compilecmp tool:
compilecmp local/master -> HEAD
local/master (
|
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
AUTHORS | ||
CONTRIBUTING.md | ||
CONTRIBUTORS | ||
LICENSE | ||
PATENTS | ||
README.md | ||
SECURITY.md | ||
codereview.cfg |
README.md
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://golang.org/doc/contribute.html.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.