-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Open
Labels
Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
func f(x int, b bool) int {
if x < 0 {
x *= -1
}
if b {
return x
}
return 0
}
The compiled code for f
matches the input closely: It checks x < 0
, negates it if so, then checks b.
But we only need to check and modify x if b is true. The compiler should rewrite this code into:
func f(x int, b bool) int {
if b {
if x < 0 {
x *= -1
}
return x
}
return 0
}
This is similar to the tighten pass, but instead of operating on values, it should operate on subsections of the CFG. Similar to the tighten pass, it should avoid moving work into a loop.
Among other things, this would help avoid doing needless work when the return value of copy is unused; see https://go-review.googlesource.com/c/go/+/94596.
Marking 1.11 optimistically, although I have no plans to work on this myself.
odeke-em and ns-cweber
Metadata
Metadata
Assignees
Labels
Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.