Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
f
x < 0
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.
cc @randall77 @dr2chase @cherrymui
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The compiled code for
f
matches the input closely: It checksx < 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:
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.
cc @randall77 @dr2chase @cherrymui
The text was updated successfully, but these errors were encountered: