Skip to content

Commit

Permalink
JIT: Allow jump-to-next-block removal for blocks with alignment (#97011)
Browse files Browse the repository at this point in the history
Fixes #96998. The jump-to-next-block removal optimization currently passes on jumps with alignment padding behind them (see BasicBlock::CanRemoveJumpToNext). While our alignment placement strategy does not consider blocks with jumps that will be removed, it is possible for such a block to be chosen if it precedes the start of the loop being aligned. This alignment decision blocks the jump from being removed. Under normal circumstances, it should be fine to remove such jumps, and just fall through the alignment padding into the next block, but JitStress might decide to place breakpoint instructions in these alignment areas if behind a jump. So in debug builds, we now tell emitter::emitLoopAlignment if the jump was removed so JitStress does not consider placing breakpoints in the alignment padding.
  • Loading branch information
amanasifkhalid authored Feb 2, 2024
1 parent 2b07375 commit cf79806
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ bool BasicBlock::IsFirstColdBlock(Compiler* compiler) const
bool BasicBlock::CanRemoveJumpToNext(Compiler* compiler) const
{
assert(KindIs(BBJ_ALWAYS));
return JumpsToNext() && !hasAlign() && !compiler->fgInDifferentRegions(this, bbTarget);
return JumpsToNext() && (bbNext != compiler->fgFirstColdBlock);
}

//------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ void CodeGen::genCodeForBBlist()

/* Do we need to generate a jump or return? */

bool removedJmp = false;
switch (block->GetKind())
{
case BBJ_RETURN:
Expand Down Expand Up @@ -765,6 +766,7 @@ void CodeGen::genCodeForBBlist()
}
#endif // TARGET_AMD64

removedJmp = true;
break;
}
#ifdef TARGET_XARCH
Expand Down Expand Up @@ -814,7 +816,7 @@ void CodeGen::genCodeForBBlist()
assert(!block->KindIs(BBJ_CALLFINALLY));
#endif // FEATURE_EH_CALLFINALLY_THUNKS

GetEmitter()->emitLoopAlignment(DEBUG_ARG1(block->KindIs(BBJ_ALWAYS)));
GetEmitter()->emitLoopAlignment(DEBUG_ARG1(block->KindIs(BBJ_ALWAYS) && !removedJmp));
}

if (!block->IsLast() && block->Next()->isLoopAlign())
Expand Down

0 comments on commit cf79806

Please sign in to comment.