Skip to content

Commit adc4d2c

Browse files
committed
cmd/compile: run deadcode before nilcheck for better statement relocation
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>
1 parent 08a8793 commit adc4d2c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/cmd/compile/internal/ssa/compile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ var passes = [...]pass{
409409
{name: "opt deadcode", fn: deadcode, required: true}, // remove any blocks orphaned during opt
410410
{name: "generic cse", fn: cse},
411411
{name: "phiopt", fn: phiopt},
412+
{name: "gcse deadcode", fn: deadcode, required: true}, // clean out after cse and phiopt
412413
{name: "nilcheckelim", fn: nilcheckelim},
413414
{name: "prove", fn: prove},
414415
{name: "fuse plain", fn: fusePlain},

test/prove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ func sm1(b []int, x int) {
507507
useSlice(b[2:8]) // ERROR "Proved slicemask not needed$"
508508
// Test non-constant argument with known limits.
509509
if cap(b) > 10 {
510-
useSlice(b[2:]) // ERROR "Proved slicemask not needed$"
510+
useSlice(b[2:])
511511
}
512512
}
513513

0 commit comments

Comments
 (0)