From adc4d2cc2dbc20c14bae7bbdbca8d75421e1bef5 Mon Sep 17 00:00:00 2001 From: David Chase Date: Mon, 30 Sep 2019 11:12:29 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller --- src/cmd/compile/internal/ssa/compile.go | 1 + test/prove.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go index f061b624483..1a0a46c154c 100644 --- a/src/cmd/compile/internal/ssa/compile.go +++ b/src/cmd/compile/internal/ssa/compile.go @@ -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}, diff --git a/test/prove.go b/test/prove.go index 6629982ba85..00fc94e7219 100644 --- a/test/prove.go +++ b/test/prove.go @@ -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:]) } }