JIT: improve simplification of IND(ADDR(x)) (dotnet/coreclr#20508)
authorAndy Ayers <andya@microsoft.com>
Mon, 22 Oct 2018 20:14:57 +0000 (13:14 -0700)
committerGitHub <noreply@github.com>
Mon, 22 Oct 2018 20:14:57 +0000 (13:14 -0700)
Some `IND(ADDR(x))` trees were not being optimized to `x` by morph,
particularly when `x` was the promoted pointer field of a `Span`.
Instead they were creating local fields that blocked enregistration
and lead to store-load pairs like:

```asm
       mov      bword ptr [rsp+20H], rax
       mov      rax, bword ptr [rsp+20H]
```

Add logic to `fgMorphSmpOp`'s `GT_IND` clause to recognize and simplify
these cases.

Commit migrated from https://github.com/dotnet/coreclr/commit/c0aa74fe584a04f8c7c8e81882793a136ee074d9

src/coreclr/src/jit/morph.cpp

index 022bf35..1f6de01 100644 (file)
@@ -13066,6 +13066,12 @@ DONE_MORPHING_CHILDREN:
                         tree->gtType = typ = temp->TypeGet();
                         foldAndReturnTemp  = true;
                     }
+                    else if (!varTypeIsStruct(typ) && (lvaTable[lclNum].lvType == typ) &&
+                             !lvaTable[lclNum].lvNormalizeOnLoad())
+                    {
+                        tree->gtType = typ = temp->TypeGet();
+                        foldAndReturnTemp  = true;
+                    }
                     else
                     {
                         // Assumes that when Lookup returns "false" it will leave "fieldSeq" unmodified (i.e.