Skip to content

JIT: type assertion prop doesn't know declared types for args or locals #9057

@AndyAyersMS

Description

@AndyAyersMS

This limits the ability to reason about subtypes. For instance in the following example the jit cannot optimize away the cast:

using System;
using System.Collections.Generic;

class Program
{
    static void Main() => MyMethod(new char[0]);

    static void MyMethod<T>(IEnumerable<T> chars)
    {
        if (typeof(T) == typeof(char))
        {
            foreach (char c in (IEnumerable<char>)chars) { }
        }
    }
}

One idea here is to allow assertion prop to fall back to querying known sources of type information, eg gtGetClassHandle, when assertions are lacking. One might also consider teaching assertion prop that sealed classes are particularly interesting.

Likely however, most interesting cases of this kind can be caught earlier and with better effect (since this may unblock devirt/inlining or streamline importation), so it may not be worth doing anything here, once the anticipated cast optimizations in the importer are implemented.

category:cq
theme:assertion-prop
skill-level:expert
cost:medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    JitUntriagedCLR JIT issues needing additional triagearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions