[dev.ssa] cmd/compile/ssa: add nilcheckelim pass

The nilcheckelim pass eliminates unnecessary nil checks.
The initial implementation removes redundant nil checks.
See the comments in nilcheck.go for ideas for future
improvements.

The efficacy of the cse pass has a significant impact
on this efficacy of this pass.

There are 886 nil checks in the parts of the standard
library that SSA can currently compile (~20%).

This pass eliminates 75 (~8.5%) of them.

As a data point, with a more aggressive but unsound
cse pass that treats many more types as identical,
this pass eliminates 115 (~13%) of the nil checks.

Change-Id: I13e567a39f5f6909fc33434d55c17a7e3884a704
Reviewed-on: https://go-review.googlesource.com/11430
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Josh Bleecher Snyder 2015-06-03 12:31:47 -07:00
parent 8c6abfeacb
commit 2a846d2bd3
4 changed files with 89 additions and 1 deletions

View file

@ -24,7 +24,11 @@ func cse(f *Func) {
// until it reaches a fixed point.
// Make initial partition based on opcode/type/aux/nargs
// TODO(khr): types are not canonical, so we may split unnecessarily. Fix that.
// TODO(khr): types are not canonical, so we split unnecessarily.
// For example, all pointer types are distinct. Fix this.
// As a data point, using v.Type.String() instead of
// v.Type here (which is unsound) allows removal of
// about 50% more nil checks in the nilcheck elim pass.
type key struct {
op Op
typ Type