No const arg to temp (#48308)
authorAlex Covington <68252706+alexcovington@users.noreply.github.com>
Fri, 19 Feb 2021 17:55:18 +0000 (09:55 -0800)
committerGitHub <noreply@github.com>
Fri, 19 Feb 2021 17:55:18 +0000 (09:55 -0800)
* Starting to add IsInvariant helper

* Finished IsInvariant helper. Starting testing

* Removed IsInvariant from GenTree to avoid asserts

* Formatting

* Fixed missing not operator

* Changed AsOp() call to 'this' to avoid failing assertions

* Formatting

* Update src/coreclr/jit/morph.cpp

Co-authored-by: Sergey Andreenko <seandree@microsoft.com>
* Update src/coreclr/jit/compiler.h

Co-authored-by: Sergey Andreenko <seandree@microsoft.com>
* Apply suggestions from code review

Co-authored-by: Sergey Andreenko <seandree@microsoft.com>
* Change arguments to const to avoid cast

* Formatting

* delete `IsInvariant` from Compiler.

Co-authored-by: Sergey Andreenko <seandree@microsoft.com>
src/coreclr/jit/compiler.h
src/coreclr/jit/gentree.cpp
src/coreclr/jit/gentree.h
src/coreclr/jit/importer.cpp
src/coreclr/jit/morph.cpp

index b69c0c1..51cf6d6 100644 (file)
@@ -4368,7 +4368,7 @@ private:
     static LONG jitNestingLevel;
 #endif // DEBUG
 
-    static BOOL impIsAddressInLocal(GenTree* tree, GenTree** lclVarTreeOut);
+    static BOOL impIsAddressInLocal(const GenTree* tree, GenTree** lclVarTreeOut);
 
     void impMakeDiscretionaryInlineObservations(InlineInfo* pInlineInfo, InlineResult* inlineResult);
 
@@ -10396,7 +10396,6 @@ public:
     GenTree* fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntryPtr);
 
     bool killGCRefs(GenTree* tree);
-
 }; // end of class Compiler
 
 //---------------------------------------------------------------------------------------------------------------------
index c359bef..794a1ef 100644 (file)
@@ -2845,7 +2845,7 @@ bool Compiler::gtCanSwapOrder(GenTree* firstNode, GenTree* secondNode)
             if (firstNode->gtFlags & strictEffects & GTF_PERSISTENT_SIDE_EFFECTS)
             {
                 // We have to be conservative - can swap iff op2 is constant.
-                if (!secondNode->OperIsConst())
+                if (!secondNode->IsInvariant())
                 {
                     canSwap = false;
                 }
@@ -19598,3 +19598,9 @@ bool GenTreeLclFld::IsOffsetMisaligned() const
     return false;
 }
 #endif // TARGET_ARM
+
+bool GenTree::IsInvariant() const
+{
+    GenTree* lclVarTree = nullptr;
+    return OperIsConst() || Compiler::impIsAddressInLocal(this, &lclVarTree);
+}
index d29db8b..b475504 100644 (file)
@@ -2189,10 +2189,12 @@ private:
 public:
     bool Precedes(GenTree* other);
 
+    bool IsInvariant() const;
+
     bool IsReuseRegVal() const
     {
         // This can be extended to non-constant nodes, but not to local or indir nodes.
-        if (OperIsConst() && ((gtFlags & GTF_REUSE_REG_VAL) != 0))
+        if (IsInvariant() && ((gtFlags & GTF_REUSE_REG_VAL) != 0))
         {
             return true;
         }
@@ -2200,12 +2202,12 @@ public:
     }
     void SetReuseRegVal()
     {
-        assert(OperIsConst());
+        assert(IsInvariant());
         gtFlags |= GTF_REUSE_REG_VAL;
     }
     void ResetReuseRegVal()
     {
-        assert(OperIsConst());
+        assert(IsInvariant());
         gtFlags &= ~GTF_REUSE_REG_VAL;
     }
 
index 63c4c37..e8f12dc 100644 (file)
@@ -18921,7 +18921,7 @@ bool Compiler::impIsValueType(typeInfo* pTypeInfo)
 
  */
 
-BOOL Compiler::impIsAddressInLocal(GenTree* tree, GenTree** lclVarTreeOut)
+BOOL Compiler::impIsAddressInLocal(const GenTree* tree, GenTree** lclVarTreeOut)
 {
     if (tree->gtOper != GT_ADDR)
     {
@@ -19450,7 +19450,7 @@ void Compiler::impInlineRecordArgInfo(InlineInfo*   pInlineInfo,
         INDEBUG(curArgVal->AsLclVar()->gtLclILoffs = argNum;)
     }
 
-    if ((curArgVal->OperKind() & GTK_CONST) || isAddressInLocal)
+    if (curArgVal->IsInvariant())
     {
         inlCurArgInfo->argIsInvariant = true;
         if (inlCurArgInfo->argIsThis && (curArgVal->gtOper == GT_CNS_INT) && (curArgVal->AsIntCon()->gtIconVal == 0))
index 94f9863..0c07628 100644 (file)
@@ -1340,9 +1340,7 @@ void fgArgInfo::ArgsComplete()
                 fgArgTabEntry* prevArgTabEntry = argTable[prevInx];
                 assert(prevArgTabEntry->argNum < curArgTabEntry->argNum);
 
-                // TODO-CQ: We should also allow LCL_VAR_ADDR and LCL_FLD_ADDR here, they're
-                // side effect free leaf nodes that like constant can be evaluated at any point.
-                if (prevArgTabEntry->GetNode()->gtOper != GT_CNS_INT)
+                if (!prevArgTabEntry->GetNode()->IsInvariant())
                 {
                     prevArgTabEntry->needTmp = true;
                     needsTemps               = true;