From ff6af23ae9d03b3b72b2bfe01ee665f7062c6ee4 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 2 May 2022 23:16:24 +0200 Subject: [PATCH] Remove GTF_GLOB_REF on a few more addressing nodes (#68741) GTF_GLOB_REF is necessary on a GT_ADDR node only if the child actually uses a tree with this flag as a value (and not as a location). This removes the flag in a few more places by using IsLocalAddrExpr. Fixes #68669 --- src/coreclr/jit/fgdiagnostic.cpp | 4 ++-- src/coreclr/jit/morph.cpp | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/coreclr/jit/fgdiagnostic.cpp b/src/coreclr/jit/fgdiagnostic.cpp index 1ddeaecffdfc7..d5b3cb54683e1 100644 --- a/src/coreclr/jit/fgdiagnostic.cpp +++ b/src/coreclr/jit/fgdiagnostic.cpp @@ -3085,8 +3085,8 @@ void Compiler::fgDebugCheckFlags(GenTree* tree) return GenTree::VisitResult::Continue; }); - // ADDR nodes break the "parent flags >= operands flags" invariant for GTF_GLOB_REF. - if (tree->OperIs(GT_ADDR) && op1->OperIs(GT_LCL_VAR, GT_LCL_FLD)) + // Addresses of locals never need GTF_GLOB_REF + if (tree->OperIs(GT_ADDR) && tree->IsLocalAddrExpr()) { expectedFlags &= ~GTF_GLOB_REF; } diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index c9fa5364c7458..224309aa4adbe 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -1769,6 +1769,12 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) if (setupArg != nullptr) { arg.SetEarlyNode(setupArg); + + // Make sure we do not break recognition of retbuf-as-local + // optimization here. If this is hit it indicates that we are + // unnecessarily creating temps for some ret buf addresses, and + // gtCallGetDefinedRetBufLclAddr relies on this not to happen. + noway_assert((arg.GetWellKnownArg() != WellKnownArg::RetBuffer) || !call->IsOptimizingRetBufAsLocal()); } arg.SetLateNode(defArg); @@ -1776,10 +1782,6 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) lateTail = &arg.LateNextRef(); } - // Make sure we did not do anything here that stops us from being able to - // find the local ret buf if we are optimizing it. - noway_assert(!call->IsOptimizingRetBufAsLocal() || (comp->gtCallGetDefinedRetBufLclAddr(call) != nullptr)); - #ifdef DEBUG if (comp->verbose) { @@ -11171,10 +11173,10 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) } } - /* Morphing along with folding and inlining may have changed the - * side effect flags, so we have to reset them - * - * NOTE: Don't reset the exception flags on nodes that may throw */ + // Morphing along with folding and inlining may have changed the + // side effect flags, so we have to reset them + // + // NOTE: Don't reset the exception flags on nodes that may throw assert(tree->gtOper != GT_CALL); @@ -11183,11 +11185,14 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) tree->gtFlags &= ~GTF_CALL; } - /* Propagate the new flags */ + // Propagate the new flags tree->gtFlags |= (op1->gtFlags & GTF_ALL_EFFECT); - // &aliasedVar doesn't need GTF_GLOB_REF, though alisasedVar does - if (oper == GT_ADDR && (op1->gtOper == GT_LCL_VAR)) + // addresses of locals do not need GTF_GLOB_REF, even if the child has + // it (is address exposed). Note that general addressing may still need + // GTF_GLOB_REF, for example if the subtree has a comma that involves a + // global reference. + if (tree->OperIs(GT_ADDR) && ((tree->gtFlags & GTF_GLOB_REF) != 0) && tree->IsLocalAddrExpr()) { tree->gtFlags &= ~GTF_GLOB_REF; }