From ee1dc4888e1dd9ef3ef52115d2396059cd962459 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 29 Jun 2022 17:26:19 +0200 Subject: [PATCH] JIT: Avoid introducing GT_NULLCHECK in gtTryRemoveBoxUpstreamEffects Adding GT_NULLCHECK nodes requires knowledge of which basic block the nullcheck will end up in. We do not have this easily available in all places this method is called, and regardless using GT_NULLCHECK here has minimal diffs. Fix #71193 --- src/coreclr/jit/earlyprop.cpp | 10 ++-------- src/coreclr/jit/gentree.cpp | 3 ++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/coreclr/jit/earlyprop.cpp b/src/coreclr/jit/earlyprop.cpp index e9b9eabd6d6c50..49b878d13346aa 100644 --- a/src/coreclr/jit/earlyprop.cpp +++ b/src/coreclr/jit/earlyprop.cpp @@ -69,10 +69,8 @@ void Compiler::optCheckFlagsAreSet(unsigned methodFlag, // optEarlyProp: The entry point of the early value propagation. // // Notes: -// This phase performs an SSA-based value propagation, including -// 1. Array length propagation. -// 2. Runtime type handle propagation. -// 3. Null check folding. +// This phase performs an SSA-based value propagation, including array +// length propagation and null check folding. // // For array length propagation, a demand-driven SSA-based backwards tracking of constant // array lengths is performed at each array length reference site which is in form of a @@ -83,10 +81,6 @@ void Compiler::optCheckFlagsAreSet(unsigned methodFlag, // GT_ARR_LENGTH node will then be rewritten to a GT_CNS_INT node if the array length is // constant. // -// Similarly, the same algorithm also applies to rewriting a method table (also known as -// vtable) reference site which is in form of GT_INDIR node. The base pointer, which is -// an object reference pointer, is treated in the same way as an array reference pointer. -// // Null check folding tries to find GT_INDIR(obj + const) that GT_NULLCHECK(obj) can be folded into // and removed. Currently, the algorithm only matches GT_INDIR and GT_NULLCHECK in the same basic block. diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 237e59b0e61fb0..dbb0e56ec05693 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -13866,7 +13866,8 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions if (options == BR_REMOVE_AND_NARROW || options == BR_REMOVE_AND_NARROW_WANT_TYPE_HANDLE) { JITDUMP(" to read first byte of struct via modified [%06u]\n", dspTreeID(copySrc)); - gtChangeOperToNullCheck(copySrc, compCurBB); + copySrc->ChangeOper(GT_IND); + copySrc->ChangeType(TYP_BYTE); } else {