Uh oh!
There was an error while loading. Please reload this page.
Late cast expansion: remove the null check if possible - #97234
Conversation
ghost
commented
Jan 19, 2024
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 warmupfor(inti=0;i<200;i++){Test(newProgram());Thread.Sleep(10);}[MethodImpl(MethodImplOptions.NoInlining)]voidTest(object?o){if(o!=null){if(oisProgram){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 |
jakobbotsch
commented
Jan 22, 2024
Yes, we have a number of flags that alter semantics, I'm ok with merging this as is (with the |
EgorBo
commented
Feb 7, 2024
@jakobbotsch I've fixed the GenTreeCall::Equals case + I addressed your other feedback regarding removing the debug only flag and gtGetEffectiveValue |
EgorBo
commented
Feb 7, 2024
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.