Skip to content

Codegen difference: Local vs IL Stack #75206

Description

@deeprobin

Sharplab

public 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.
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributors

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions