Skip to content

Commit

Permalink
cmd/compile: run deadcode before nilcheck for better statement reloca…
Browse files Browse the repository at this point in the history
…tion

Nilcheck would move statements from NilCheck values to others that
turned out were already dead, which leads to lost statements.  Better
to eliminate the dead code first.

One "error" is removed from test/prove.go because the code is
actually dead, and the additional deadcode pass removes it before
prove can run.

Change-Id: If75926ca1acbb59c7ab9c8ef14d60a02a0a94f8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/198479
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
  • Loading branch information
dr2chase committed Oct 3, 2019
1 parent 08a8793 commit adc4d2c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cmd/compile/internal/ssa/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ var passes = [...]pass{
{name: "opt deadcode", fn: deadcode, required: true}, // remove any blocks orphaned during opt
{name: "generic cse", fn: cse},
{name: "phiopt", fn: phiopt},
{name: "gcse deadcode", fn: deadcode, required: true}, // clean out after cse and phiopt
{name: "nilcheckelim", fn: nilcheckelim},
{name: "prove", fn: prove},
{name: "fuse plain", fn: fusePlain},
Expand Down
2 changes: 1 addition & 1 deletion test/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func sm1(b []int, x int) {
useSlice(b[2:8]) // ERROR "Proved slicemask not needed$"
// Test non-constant argument with known limits.
if cap(b) > 10 {
useSlice(b[2:]) // ERROR "Proved slicemask not needed$"
useSlice(b[2:])
}
}

Expand Down

0 comments on commit adc4d2c

Please sign in to comment.