Skip to content
Closed
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
8 changes: 4 additions & 4 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4946,6 +4946,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

if (opts.OptimizationEnabled())
{
// Conditional to switch conversion, and switch peeling
//
DoPhase(this, PHASE_SWITCH_RECOGNITION, &Compiler::optRecognizeAndOptimizeSwitchJumps);

// Optimize boolean conditions
//
DoPhase(this, PHASE_OPTIMIZE_BOOLS, &Compiler::optOptimizeBools);
Expand All @@ -4954,10 +4958,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
//
DoPhase(this, PHASE_IF_CONVERSION, &Compiler::optIfConversion);

// Conditional to switch conversion, and switch peeling
//
DoPhase(this, PHASE_SWITCH_RECOGNITION, &Compiler::optRecognizeAndOptimizeSwitchJumps);

// Run flow optimizations before reordering blocks
//
DoPhase(this, PHASE_OPTIMIZE_PRE_LAYOUT, &Compiler::optOptimizePreLayout);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/optimizebools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ bool Compiler::fgFoldCondToReturnBlock(BasicBlock* block)
modified = true;
}
// Same here - bail out if the block is no longer BBJ_COND after compacting.
if (!block->KindIs(BBJ_COND))
if (block->HasFlag(BBF_REMOVED) || !block->KindIs(BBJ_COND))
{
return modified;
}
Expand Down
23 changes: 23 additions & 0 deletions src/coreclr/jit/switchrecognition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ PhaseStatus Compiler::optRecognizeAndOptimizeSwitchJumps()
continue;
}

// Before we start, let's optimize possible fallthrough blocks for BBJ_COND's successors.
if (block->KindIs(BBJ_COND) && block->hasSingleStmt())
{
BasicBlock* retFalseBb = block->GetFalseTarget();
BasicBlock* retTrueBb = block->GetTrueTarget();
if (fgCanCompactBlock(retTrueBb) && retTrueBb->isEmpty())
{
fgCompactBlock(retTrueBb);
modified = true;
}
// fgCompactBlock could have removed retFalseBb and the block, so we
// need to check BBF_REMOVED flag for both.
if (!retFalseBb->HasFlag(BBF_REMOVED) && fgCanCompactBlock(retFalseBb))
{
fgCompactBlock(retFalseBb);
modified = true;
}
if (block->HasFlag(BBF_REMOVED))
{
continue;
}
}

// Limit to XARCH, ARM is already doing a great job with such comparisons using
// a series of ccmp instruction (see ifConvert phase).
#ifdef TARGET_XARCH
Expand Down
Loading