-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Late cast expansion: remove the null check if possible #97234
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsIf assertionprop sees that input object is already having a nonnull assertion we can give fgLateCastExpand a hint that we don't need a nullcheck, example: // PGO warmup
for (int i = 0; i < 200; i++)
{
Test(new Program());
Thread.Sleep(10);
}
[MethodImpl(MethodImplOptions.NoInlining)]
void Test(object? o)
{
if (o != null)
{
if (o is Program)
{
Console.WriteLine();
}
}
} Diff: https://www.diffchecker.com/JkdxRigp/ Initially, I wanted to just introduce new _NONNULL cast helpers, but this change seems to be a lot smaller. In case if we run out of bits in gtMoreCallFlags in can be removed in favor of _NONNULL helpers.
|
@dotnet/jit-contrib @jakobbotsch PTAL
Overall it looks like if we run out of spare bits we can move some rare things to side dictionaries or make some of them context-dependent. E.g. 3 GDV flags are only needed for virtual calls and only during early phases. Diffs aren't too big, but they will be a lot bigger once I move non-profiled (regular) casts to the late phase. Build failures are known. |
I definitely think having separate helpers would be better, especially since it would be slightly better for unprofiled casts too (assuming we would have cast variants that skip the null check inside them). I'm ok with using a flag, but note that having flags that alter the semantics of nodes is IMO bad IR design. It's super easy to forget to check for. For example, shouldn't this PR check for the new flag inside |
I don't have a strong preference here, I'll see what it will take to use the helpers, but I am guessing it's a copy-paste of all 8 helpers everywhere + R2R version bump + JIT-EE bump.
I thought about it too, but sounds like adding extra several kb to
I agree generally, but looks like some of the existing flags already do similar things? e.g. tail call |
Yes, we have a number of flags that alter semantics, I'm ok with merging this as is (with the |
@jakobbotsch I've fixed the GenTreeCall::Equals case + I addressed your other feedback regarding removing the debug only flag and gtGetEffectiveValue |
Failure is #97049 |
If assertionprop sees that input object is already having a nonnull assertion we can give fgLateCastExpand a hint that we don't need a nullcheck, example:
Diff: https://www.diffchecker.com/JkdxRigp/
Initially, I wanted to just introduce new _NONNULL cast helpers, but this change seems to be a lot smaller. In case if we run out of bits in gtMoreCallFlags we can remove it in favor of _NONNULL helpers.