diff --git a/src/coreclr/jit/async.cpp b/src/coreclr/jit/async.cpp index cd4bb35514149e..8430ccf5be4ef2 100644 --- a/src/coreclr/jit/async.cpp +++ b/src/coreclr/jit/async.cpp @@ -1071,24 +1071,29 @@ void AsyncTransformation::LiftLIREdges(BasicBlock* block, for (GenTree* tree : defs) { - // TODO-CQ: Enable this. It currently breaks our recognition of how the - // call is stored. - // if (tree->OperIs(GT_LCL_VAR)) - //{ - // LclVarDsc* dsc = m_compiler->lvaGetDesc(tree->AsLclVarCommon()); - // if (!dsc->IsAddressExposed()) - // { - // // No interference by IR invariants. - // LIR::AsRange(block).Remove(tree); - // LIR::AsRange(block).InsertAfter(beyond, tree); - // continue; - // } - //} - LIR::Use use; bool gotUse = LIR::AsRange(block).TryGetUse(tree, &use); assert(gotUse); // Defs list should not contain unused values. + if (tree->IsInvariant()) + { + LIR::AsRange(block).Remove(tree); + LIR::AsRange(block).InsertBefore(use.User(), tree); + continue; + } + + if (tree->OperIs(GT_LCL_VAR)) + { + LclVarDsc* dsc = m_compiler->lvaGetDesc(tree->AsLclVarCommon()); + if (!dsc->IsAddressExposed()) + { + // No interference by IR invariants + LIR::AsRange(block).Remove(tree); + LIR::AsRange(block).InsertBefore(use.User(), tree); + continue; + } + } + unsigned newLclNum = use.ReplaceWithLclVar(m_compiler); layoutBuilder->AddLocal(newLclNum); GenTree* newUse = use.Def();