Skip to content

Conversation

@vargaz
Copy link
Contributor

@vargaz vargaz commented Sep 23, 2021

No description provided.

@vargaz vargaz force-pushed the type-eq-elim branch 4 times, most recently from 76ac8cf to 7a890b7 Compare September 24, 2021 02:06
@vargaz vargaz added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Sep 25, 2021
@vargaz vargaz marked this pull request as draft September 25, 2021 22:39
@vargaz vargaz force-pushed the type-eq-elim branch 2 times, most recently from 6b5f141 to 4afc5fd Compare September 26, 2021 01:13
@vargaz
Copy link
Contributor Author

vargaz commented Sep 26, 2021

The failures are related.

@vargaz
Copy link
Contributor Author

vargaz commented Sep 26, 2021

On a wasm aot hello world, this saves about 100k.

@vargaz vargaz force-pushed the type-eq-elim branch 5 times, most recently from f2d23e8 to 20b9c84 Compare September 27, 2021 11:44
Comparisons of the form
```
        internal static void ThrowForUnsupportedIntrinsicsVectorBaseType<T>() where T : struct
        {
            if (typeof(T) != typeof(byte) && typeof(T) != typeof(sbyte) &&
            ...
        }
```
are very common in BCL code. They are compiled to:
```
    IL_0001:  ldtoken    !!T
    IL_0006:  call       [System.Runtime]System.Type [System.Runtime]System.Type::GetTypeFromHandle([System.Runtime]System.RuntimeTypeHandle)
    IL_000b:  ldtoken    [System.Runtime]System.Byte
    IL_0010:  call       [System.Runtime]System.Type [System.Runtime]System.Type::GetTypeFromHandle([System.Runtime]System.RuntimeTypeHandle)
    IL_0015:  call       bool [System.Runtime]System.Type::op_Inequality([System.Runtime]System.Type,
                                                                         [System.Runtime]System.Type)
    IL_001a:  brfalse    IL_015a
```

In gshared code, !!T is usually constrained to be a reference, or to have a primitive base type.
Use this fact to eliminate some of the Type::op_Equality/op_Inequality () calls.

Fixes dotnet#54849.
@vargaz vargaz marked this pull request as ready for review September 27, 2021 21:58
@vargaz vargaz removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Sep 27, 2021
@vargaz vargaz merged commit b8db0ea into dotnet:main Sep 28, 2021
@vargaz vargaz deleted the type-eq-elim branch September 28, 2021 14:08
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants