Admit additional `ADD` patterns in `GenTree:IsFieldAddr`.
authorPat Gavlin <pagavlin@microsoft.com>
Tue, 25 Jul 2017 23:56:50 +0000 (16:56 -0700)
committerPat Gavlin <pagavlin@microsoft.com>
Tue, 25 Jul 2017 23:56:50 +0000 (16:56 -0700)
We already recognize `ADD(t, CNS_INT)` in this function. This change
extends the relevant logic to `ADD(CNS_INT, t)` iff the first operand is
a handle.

src/jit/gentree.cpp

index c6e690d..29d8cef 100644 (file)
@@ -15398,10 +15398,16 @@ bool GenTree::IsFieldAddr(Compiler* comp, GenTreePtr* pObj, GenTreePtr* pStatic,
     }
     else if (OperGet() == GT_ADD)
     {
-        // op1 should never be a field sequence (or any other kind of handle)
-        assert((gtOp.gtOp1->gtOper != GT_CNS_INT) || !gtOp.gtOp1->IsIconHandle());
-        if (gtOp.gtOp2->OperGet() == GT_CNS_INT)
+        // If one operator is a field sequence/handle, the other operator must not also be a field sequence/handle.
+        if ((gtOp.gtOp1->OperGet() == GT_CNS_INT) && gtOp.gtOp1->IsIconHandle())
         {
+            assert((gtOp.gtOp2->gtOper != GT_CNS_INT) || !gtOp.gtOp2->IsIconHandle());
+            newFldSeq = gtOp.gtOp1->AsIntCon()->gtFieldSeq;
+            baseAddr  = gtOp.gtOp2;
+        }
+        else if (gtOp.gtOp2->OperGet() == GT_CNS_INT)
+        {
+            assert((gtOp.gtOp1->gtOper != GT_CNS_INT) || !gtOp.gtOp1->IsIconHandle());
             newFldSeq = gtOp.gtOp2->AsIntCon()->gtFieldSeq;
             baseAddr  = gtOp.gtOp1;
         }