Fix GenTree hash function for commutative operators
authorBruce Forstall <brucefo@microsoft.com>
Tue, 24 Jan 2017 01:19:30 +0000 (17:19 -0800)
committerBruce Forstall <brucefo@microsoft.com>
Tue, 24 Jan 2017 01:24:40 +0000 (17:24 -0800)
gtHashValue() computes a hash value for a tree that, at least now,
is only used for determining whether to display the tree in the
JitDump after morphing. The hash function for commutative binary
operators was designed to return the same value if the operands
were switched (possibly this was used for CSE previously?). However,
this means that in some cases, nearly symmetric operands before and
after morphing would cause the "after morph" tree not to be displayed,
which is very confusing, since it implies that morphing had no
effect on the tree.

Since it appears we have no need for this special handling of
commutative binary operators, remove the special hashing done for them.

src/jit/compiler.h
src/jit/gentree.cpp

index 54079b9..cce4dfb 100644 (file)
@@ -2070,13 +2070,13 @@ public:
 
     bool gtHasLocalsWithAddrOp(GenTreePtr tree);
 
-    unsigned gtHashValue(GenTree* tree);
-
     unsigned gtSetListOrder(GenTree* list, bool regs, bool isListCallArgs);
 
     void gtWalkOp(GenTree** op1, GenTree** op2, GenTree* adr, bool constOnly);
 
 #ifdef DEBUG
+    unsigned gtHashValue(GenTree* tree);
+
     GenTreePtr gtWalkOpEffectiveVal(GenTreePtr op);
 #endif
 
index 7ed7be4..a9de460 100644 (file)
@@ -2686,6 +2686,8 @@ bool Compiler::gtHasLocalsWithAddrOp(GenTreePtr tree)
     return desc.hasAddrTakenLcl;
 }
 
+#ifdef DEBUG
+
 /*****************************************************************************
  *
  *  Helper used to compute hash values for trees.
@@ -2701,11 +2703,6 @@ inline unsigned genTreeHashAdd(unsigned old, void* add)
     return genTreeHashAdd(old, (unsigned)(size_t)add);
 }
 
-inline unsigned genTreeHashAdd(unsigned old, unsigned add1, unsigned add2)
-{
-    return (old + old / 2) ^ add1 ^ add2;
-}
-
 /*****************************************************************************
  *
  *  Given an arbitrary expression tree, compute a hash value for it.
@@ -2900,18 +2897,6 @@ AGAIN:
 
         unsigned hsh1 = gtHashValue(op1);
 
-        /* Special case: addition of two values */
-
-        if (GenTree::OperIsCommutative(oper))
-        {
-            unsigned hsh2 = gtHashValue(op2);
-
-            /* Produce a hash that allows swapping the operands */
-
-            hash = genTreeHashAdd(hash, hsh1, hsh2);
-            goto DONE;
-        }
-
         /* Add op1's hash to the running value and continue with op2 */
 
         hash = genTreeHashAdd(hash, hsh1);
@@ -3027,6 +3012,8 @@ DONE:
     return hash;
 }
 
+#endif // DEBUG
+
 /*****************************************************************************
  *
  *  Given an arbitrary expression tree, attempts to find the set of all local variables