-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Codegen difference: Local vs IL Stack #75206
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue Detailspublic class C {
public int A(int i) {
i += 2;
i += 4;
return i;
}
public int B(int i) {
var j = i;
j += 2;
j += 4;
return j;
}
public int ConsumeA(int i) => A(i);
public int ConsumeB(int i) => B(i);
} According to @SingleAccretion, this is because Roslyn prefers to use the IL stack for locals instead of parameters. I would argue that there is a real-world case, as I have seen code where no new variable was created but the parameter was modified directly.
|
The optimization for locals is fairly simple and can be done in global morph (a bit like the SIMD assignment coalescence works right now). The perhaps more interesting case is making this work for indirect (aka field) stores: *p += 4;
*p += 4;
=>
*p += 8; This would have the benefit of avoiding relatively expensive memory operations, but would also require more thorough analysis to determine legality. |
Forward sub and or VN prop might also be places to consider. Forward sub is currently blocked by the fact that these sorts of locals have many appearances, but if there are adjacent statements that both def the same local..... |
Sharplab
According to @SingleAccretion, this is because Roslyn prefers to use the IL stack for locals instead of parameters.
So an optimization would make sense for this.
I would argue that there is a real-world case, as I have seen code where no new variable was created but the parameter was modified directly.
The text was updated successfully, but these errors were encountered: