-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/compile: elide branches that must be taken #17862
New issue
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
Comments
Did you mean to say that version A is 25% faster? Because otherwise I don't understand. The traditional compiler optimization to fix this is Value Range Propagation. |
@dsnet, I'm not sure I understand the issue here. Since A, B, and C are variables, some code outside of the benchmarks could modify these, and then the benchmark functions would have to take the panic branch. We can't statically eliminate that. If A, B, and C are consts, then the compiler will recognize that it can statically prove the panic branch condition and will eliminate the panic branch in both benchmarks. Perhaps you're suggesting that the compiler should recognize that it can lift the panic |
@aclements The issue is that m is local, so it's not being modified elsewhere. One way to look at this is that conditional A is followed by conditional B, and both arms of A determine subsequent execution of B. B could be "inlined" (as a continuation, exactly that) into the two arms of A and then simplified. |
Uh oh!
There was an error while loading. Please reload this page.
Consider the following two benchmarks:
On Go 1.8, version A is 25%
slowerfaster than version B. The reason for this is because the compiler actually setsm = -1
and then does the subsequent conditional checkm == -1
. The compiler should be able to prove that this unnecessary.Code that looks like this commonly occurs when a smaller inlineable helper is used for a quick path and then a conditional is used to check for a fallback. For example:
This came up in http://golang.org/cl/32921.
/cc @bradfitz @randall77
The text was updated successfully, but these errors were encountered: