]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: use Block.Likely to put likely branch first
authorDavid Chase <drchase@google.com>
Thu, 5 Apr 2018 20:14:42 +0000 (16:14 -0400)
committerDavid Chase <drchase@google.com>
Wed, 11 Apr 2018 17:35:34 +0000 (17:35 +0000)
commitab48574bab55eec033c4fed7f7eb4cedfaef90aa
treed3925ff6f0b4ebea6b2c292b502e44c704141009
parent2b239969390553726d5042e723b344f897bf810d
cmd/compile: use Block.Likely to put likely branch first

When a neither of a conditional block's successors follows,
the block must end with a conditional branch followed by a
an unconditional branch.  If the (conditional) branch is
"unlikely", invert it and swap successors to make it
likely instead.

This doesn't matter to most benchmarks on amd64, but in one
instance on amd64 it caused a 30% improvement, and it is
otherwise harmless.  The problematic loop is

for i := 0; i < w; i++ {
if pw[i] != 0 {
return true
}
}

compiled under GOEXPERIMENT=preemptibleloops
This the very worst-case benchmark for that experiment.

Also in this CL is a commoning up of heavily-repeated
boilerplate, which made it much easier to see that the
changes were applied correctly.  In the future this should
allow un-exporting of SSAGenState.Branches once the
boilerplate-replacement is done everywhere.

Change-Id: I0e5ded6eeb3ab1e3e0138e12d54c7e056bd99335
Reviewed-on: https://go-review.googlesource.com/104977
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/amd64/ssa.go
src/cmd/compile/internal/arm/ssa.go
src/cmd/compile/internal/arm64/ssa.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/mips/ssa.go
src/cmd/compile/internal/mips64/ssa.go
src/cmd/compile/internal/ppc64/ssa.go
src/cmd/compile/internal/s390x/ssa.go
src/cmd/compile/internal/x86/ssa.go