-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Open
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
nilcheckelim is effective and fast, but only eliminates nil checks. There are other kinds of duplicate branches that it would be nice to also elide.
For example, consider code like:
func f_ssa(e interface{}) int {
if e.(int) < 0 {
return -1
}
return e.(int) * 2
}
Each of the type assertions will generate a branch to check e's dynamic type, but the subsequent checks are unnecessary, and could be eliminated with very similar logic to nilcheckelim. Code like this, in which an interface is type asserted repeatedly, shows up in the compiler, so it is not theoretical.
I'd expect the souped-up optimization to also handle (silly) code like:
func f_ssa(i int) int {
var x int
if i < 3 {
x += 1
}
if i < 3 {
x += 2
}
return x
}
(The compiled code should only have one branch.)
Metadata
Metadata
Assignees
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.