Description
This is a follow-up for #44059.
There are 2 methods that create GT_NULLCHECK
: gtNewNullCheck
and gtChangeOperToNullCheck
.
We have added an assert assert(fgAddrCouldBeNull(addr))
to gtNewNullCheck
and it could be profitable to add the same assert to gtChangeOperToNullCheck
to delete unnecessary null-checks earlier and sometimes allow the later phase to generate better code.
The difficulty is that gtChangeOperToNullCheck
is used in different phases and in some of them it is not easy to delete an unnecessary node. An easier solution would be to replace the node with a nop and allow later phases to delete it also hit some asserts (prototype ),
for example in
runtime\artifacts\tests\coreclr\Windows_NT.x64.Checked\Tests\Core_Root\CoreRun.exe "jitutils\bin\pmi.dll" PrepOne runtime\artifacts\tests\coreclr\Windows_NT.x64.Release\Tests\Core_Root\mscorlib.dll 5480
we try to hoist such expression:
[000048] n----+------ | +--* OBJ simd32<System.Numerics.Vector`1[Single]> // note that `n` in the flags means non-faulting.
[000044] -----+-N---- | | \--* LCL_VAR byref V01 arg1
and we create
[000092] ----G------- * COMMA void
( 7, 5) [000089] n---G--H---- +--* OBJ simd32<System.Numerics.Vector`1[Single]> <l:$341, c:$382>
( 1, 1) [000090] -------N---- | \--* LCL_VAR byref V01 arg1 u:1 $81
[000091] ------------ \--* NOP void
and call gtExtractSideEffList
on 000089
, gtExtractSideEffList
can't drop the tree because it is marked as GTF_MAKE_CSE
so it will try to call gtChangeOperToNullCheck
on an OBJ
that can't fail.
The resulting tree with the current master is:
***** BB06
STMT00012 (IL ???... ???)
N004 ( 2, 2) [000092] ----G------- * COMMA void
N002 ( 2, 2) [000089] ----G--H---- +--* NULLCHECK int
N001 ( 1, 1) [000090] -------N---- | \--* LCL_VAR byref V01 arg1 u:1 $81
N003 ( 0, 0) [000091] ------------ \--* NOP void
it is not clear how would we like to transform it, because if the tree should be just deleted why did we choose this node for loop hoisting?
Note: I have run asm diffs with the prototype and have not seen asm diffs except for failing methods, so fixing this issue could be a clean-up only, rather than CQ, but it is not certain.
cc @AndyAyersMS
category:cq
theme:null-checks