Remove potential NULLCHECK creation after LIR on arm32. (#40349)
authorSergey Andreenko <seandree@microsoft.com>
Wed, 5 Aug 2020 04:02:17 +0000 (21:02 -0700)
committerGitHub <noreply@github.com>
Wed, 5 Aug 2020 04:02:17 +0000 (21:02 -0700)
* Use `TransformUnusedIndirection` in LIR liveness.

* Use `TYP_INT` as `TransformUnusedIndirection` does.

* fix grammar.

src/coreclr/src/jit/compiler.cpp
src/coreclr/src/jit/liveness.cpp
src/coreclr/src/jit/lower.cpp

index 4e1140e..b836a2e 100644 (file)
@@ -9293,11 +9293,16 @@ bool Compiler::lvaIsOSRLocal(unsigned varNum)
 //    tree       - the node to change;
 //    basicBlock - basic block of the node.
 //
+// Notes:
+//    the function should not be called after lowering for platforms that do not support
+//    emitting NULLCHECK nodes, like arm32. Use `Lowering::TransformUnusedIndirection`
+//    that handles it and calls this function when appropriate.
+//
 void Compiler::gtChangeOperToNullCheck(GenTree* tree, BasicBlock* block)
 {
     assert(tree->OperIs(GT_FIELD, GT_IND, GT_OBJ, GT_BLK, GT_DYN_BLK));
     tree->ChangeOper(GT_NULLCHECK);
-    tree->ChangeType(TYP_BYTE);
+    tree->ChangeType(TYP_INT);
     block->bbFlags |= BBF_HAS_NULLCHECK;
     optMethodFlags |= OMF_HAS_NULLCHECK;
 }
index 75cf6e4..5c3c860 100644 (file)
@@ -2127,8 +2127,8 @@ void Compiler::fgComputeLifeLIR(VARSET_TP& life, BasicBlock* block, VARSET_VALAR
                 if (!removed && node->IsUnusedValue())
                 {
                     // IR doesn't expect dummy uses of `GT_OBJ/BLK/DYN_BLK`.
-                    JITDUMP("Replace an unused OBJ/BLK node [%06d] with a NULLCHECK\n", dspTreeID(node));
-                    gtChangeOperToNullCheck(node, block);
+                    JITDUMP("Transform an unused OBJ/BLK node [%06d]\n", dspTreeID(node));
+                    Lowering::TransformUnusedIndirection(node->AsIndir(), this, block);
                 }
             }
             break;
index 150bfd2..61e15a3 100644 (file)
@@ -6488,7 +6488,7 @@ void Lowering::TransformUnusedIndirection(GenTreeIndir* ind, Compiler* comp, Bas
     // - On XARCH, use GT_IND if we have a contained address, and GT_NULLCHECK otherwise.
     // In all cases, change the type to TYP_INT.
     //
-    assert(ind->OperIs(GT_NULLCHECK, GT_IND));
+    assert(ind->OperIs(GT_NULLCHECK, GT_IND, GT_BLK, GT_OBJ));
 
     ind->gtType = TYP_INT;
 #ifdef TARGET_ARM64
@@ -6499,12 +6499,12 @@ void Lowering::TransformUnusedIndirection(GenTreeIndir* ind, Compiler* comp, Bas
     bool useNullCheck = !ind->Addr()->isContained();
 #endif // !TARGET_XARCH
 
-    if (useNullCheck && ind->OperIs(GT_IND))
+    if (useNullCheck && !ind->OperIs(GT_NULLCHECK))
     {
         comp->gtChangeOperToNullCheck(ind, block);
         ind->ClearUnusedValue();
     }
-    else if (!useNullCheck && ind->OperIs(GT_NULLCHECK))
+    else if (!useNullCheck && !ind->OperIs(GT_IND))
     {
         ind->ChangeOper(GT_IND);
         ind->SetUnusedValue();