Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ set( JIT_SOURCES
optimizer.cpp
patchpoint.cpp
phase.cpp
constantmaskreuse.cpp
promotion.cpp
promotiondecomposition.cpp
promotionliveness.cpp
Expand Down Expand Up @@ -338,6 +339,7 @@ set( JIT_HEADERS
compilerbitsettraits.hpp
compmemkind.h
compphases.h
constantmaskreuse.h
handlekinds.h
dataflow.h
debuginfo.h
Expand Down
56 changes: 56 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5034,6 +5034,12 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
m_pLowering = new (this, CMK_LSRA) Lowering(this, m_regAlloc); // PHASE_LOWERING
m_pLowering->Run();

#if defined(TARGET_ARM64) && defined(FEATURE_MASKED_HW_INTRINSICS)
DoPhase(this, PHASE_ARM64_CONSTANT_MASK_REUSE, &Compiler::fgOptimizeConstantMaskReuse);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, if we do this it should likely be just PHASE_CONSTANT_REUSE, we have several cases of "low cost constants" that get unnecessarily rematerialized across all architectures, including cases like zero and allbitsset

#endif

DoPhase(this, PHASE_POST_LOWERING, &Compiler::fgPostLowering);

// Set stack levels and analyze throw helper usage.
StackLevelSetter stackLevelSetter(this);
stackLevelSetter.Run();
Expand Down Expand Up @@ -5177,6 +5183,56 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
#endif // FUNC_INFO_LOGGING
}

//------------------------------------------------------------------------
// fgPostLowering: Run cleanup that depends on lowered IR.
//
// Returns:
// PhaseStatus indicating whether the IR may have been changed.
//
PhaseStatus Compiler::fgPostLowering()
{
// Recompute local var ref counts before potentially sorting for liveness.
// Note this does minimal work in cases where we are not going to sort.
const bool isRecompute = true;
const bool setSlotNumbers = false;
lvaComputeRefCounts(isRecompute, setSlotNumbers);

if (m_dfsTree == nullptr)
{
// Compute DFS tree. We want to remove dead blocks even in MinOpts, so we
// do this everywhere. The dead blocks are removed below.
m_dfsTree = fgComputeDfs();
}

// Remove dead blocks. We want to remove unreachable blocks even in MinOpts.
fgRemoveBlocksOutsideDfsTree();

if (backendRequiresLocalVarLifetimes())
{
assert(opts.OptimizationEnabled());

fgPostLowerLiveness();
// local var liveness can delete code, which may create empty blocks
bool modified = fgUpdateFlowGraph(/* doTailDuplication */ false, /* isPhase */ false);

if (modified)
{
fgDfsBlocksAndRemove();
JITDUMP("had to run another liveness pass:\n");
fgPostLowerLiveness();
}

// Recompute local var ref counts again after liveness to reflect
// impact of any dead code removal. Note this may leave us with
// tracked vars that have zero refs.
lvaComputeRefCounts(isRecompute, setSlotNumbers);
}

fgInvalidateDfsTree();

return PhaseStatus::MODIFIED_EVERYTHING;
}

//----------------------------------------------------------------------------------------------
// FinalizeEH: Finalize EH information
//
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7388,6 +7388,8 @@ class Compiler
void fgExposeLocalsInBitVec(BitVec_ValArg_T bitVec);

PhaseStatus fgOptimizeMaskConversions();
PhaseStatus fgOptimizeConstantMaskReuse();
PhaseStatus fgPostLowering();

PhaseStatus PhysicalPromotion();

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ CompPhaseNameMacro(PHASE_LCLVARLIVENESS_INTERBLOCK, "Global local var liveness"

CompPhaseNameMacro(PHASE_LOWERING_DECOMP, "Lowering decomposition", false, -1, false)
CompPhaseNameMacro(PHASE_LOWERING, "Lowering nodeinfo", false, -1, true)
CompPhaseNameMacro(PHASE_ARM64_CONSTANT_MASK_REUSE, "Arm64 SVE constant mask reuse", false, -1, true)
CompPhaseNameMacro(PHASE_POST_LOWERING, "Post-lowering cleanup", false, -1, true)
CompPhaseNameMacro(PHASE_STACK_LEVEL_SETTER, "Calculate stack level slots", false, -1, false)
CompPhaseNameMacro(PHASE_LINEAR_SCAN, "Linear scan register alloc", true, -1, true)
CompPhaseNameMacro(PHASE_LINEAR_SCAN_BUILD, "LSRA build intervals", false, PHASE_LINEAR_SCAN, false)
Expand Down
Loading
Loading