Jit: fix unnecessary null checks in some field accesses
authorAndy Ayers <andya@microsoft.com>
Thu, 13 Apr 2017 22:17:44 +0000 (15:17 -0700)
committerAndy Ayers <andya@microsoft.com>
Thu, 13 Apr 2017 22:17:44 +0000 (15:17 -0700)
commit466cf219cc42f0c88d29f94735f2c5bd2859624a
tree3190238039db925ca81665e2ffcb8957ce5fc3c8
parent45e11fc3b161c30c612af3cb0a415b5f7dfcafe6
Jit: fix unnecessary null checks in some field accesses

Morph was sometimes passing the existing MorphAddressContext down
to fgMorphField even when the field access was for a field value.
If that context contained indefinite offsets, morph would then
insert an explicit null check on the object pointer for the field
access.

Typically the field offset is small enough that this explicit check
is not needed. The implicit check done when fetching the field's value
is sufficient protection.

The fix is to have `fgMorphSmpOp` clear out the context for child
`GT_FIELD` nodes, unless the field parent is a `GT_ADDR`. Note
if there is an `op2` node the parent cannot be `GT_ADDR` so these
field children always get an empty context.

No tests added since this kicks in reasonably frequently in corelib and
elsewhere in frameworks.

Closes dotnet/coreclr#10942.

Commit migrated from https://github.com/dotnet/coreclr/commit/8936d23a89dd4508b4b5d04e93da0747ca2b7d5d
src/coreclr/src/jit/morph.cpp