JIT: don't self assign to temps (#13484)
authorAndy Ayers <andya@microsoft.com>
Wed, 23 Aug 2017 00:04:02 +0000 (17:04 -0700)
committerGitHub <noreply@github.com>
Wed, 23 Aug 2017 00:04:02 +0000 (17:04 -0700)
Modify gtNewTempAssign to more generally map self-assignment of temps
into nops.

We already were doing something similar over in `impAssignStruct`, and
now we catch non-struct cases too.

src/jit/gentree.cpp

index 66155db6a4f8f35d76c06efc51cbb8ff37dde90a..186c37b50ce30242793ecd842ea084b966283ae9 100644 (file)
@@ -13855,13 +13855,33 @@ DONE:
 #pragma warning(pop)
 #endif
 
-/*****************************************************************************
- *
- *  Create an assignment of the given value to a temp.
- */
+//------------------------------------------------------------------------
+// gtNewTempAssign: Create an assignment of the given value to a temp.
+//
+// Arguments:
+//    tmp - local number for a compiler temp
+//    val - value to assign to the temp
+//
+// Return Value:
+//    Normally a new assignment node.
+//    However may return a nop node if val is simply a reference to the temp.
+//
+// Notes:
+//    Self-assignments may be represented via NOPs.
+//
+//    May update the type of the temp, if it was previously unknown.
+//
+//    May set compFloatingPointUsed.
+//
 
 GenTreePtr Compiler::gtNewTempAssign(unsigned tmp, GenTreePtr val)
 {
+    // Self-assignment is a nop.
+    if (val->OperGet() == GT_LCL_VAR && val->gtLclVarCommon.gtLclNum == tmp)
+    {
+        return gtNewNothingNode();
+    }
+
     LclVarDsc* varDsc = lvaTable + tmp;
 
     if (varDsc->TypeGet() == TYP_I_IMPL && val->TypeGet() == TYP_BYREF)