Skip to content

Linker doesn't trim unused locals when the only usage is in initobj #1808

@tannergooding

Description

@tannergooding

Related to #1805.

If you have code such as:

Unsafe.SkipInit(out Vector128<short> value);
if (Sse.IsSupported)
{
    value = Vector128.Create(value);
}

The linker will trim out the initialization but not the Unsafe.SkipInit(out Vector128<short> value); as it doesn't recognize the call today.

If you try to refactor this to something such as:

Vector128<short> value;

if (Sse.IsSupported)
{
    value = Vector128.Create(value);
}
else
{
    value = default;
}

The linker trims it down to just: Vector128<short> value = default; but does not remove the local and therefore does not remove the now unused Vector128<T> type even though the only usage of value is in an initobj valuetype [System.Private.CoreLib]System.Runtime.Intrinsics.Vector1281` instruction.

The linker should likely recognize this scenario and trim the unused local.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions