Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Fix some cases using BasicBlock::bbFallsThrough #97699

Merged
merged 1 commit into from
Jan 30, 2024
Merged
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
12 changes: 7 additions & 5 deletions src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,11 +1123,13 @@ Statement* BasicBlock::FirstNonPhiDefOrCatchArgStore() const
return stmt;
}

/*****************************************************************************
*
* Can a BasicBlock be inserted after this without altering the flowgraph
*/

//------------------------------------------------------------------------
// bbFallsThrough: Check if inserting a BasicBlock after this one will alter
// the flowgraph.
//
// Returns:
// True if so.
//
bool BasicBlock::bbFallsThrough() const
{
switch (bbKind)
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13869,7 +13869,7 @@ void Compiler::fgMorphBlock(BasicBlock* block)
// Yes, pred assertions are available.
// If the pred is (a non-degenerate) BBJ_COND, fetch the appropriate out set.
//
ASSERT_TP assertionsOut = pred->bbAssertionOut;
ASSERT_TP assertionsOut;
const bool useCondAssertions = pred->KindIs(BBJ_COND) && (pred->NumSucc() == 2);

if (useCondAssertions)
Expand All @@ -13886,6 +13886,10 @@ void Compiler::fgMorphBlock(BasicBlock* block)
assertionsOut = pred->bbAssertionOutIfFalse;
}
}
else
{
assertionsOut = pred->bbAssertionOut;
}
Comment on lines +13889 to +13892
Copy link
Member Author

Choose a reason for hiding this comment

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

Small drive-by fix for some UB here (in the useCondAssertions case we were accessing an inactive union member).


// If this is the first pred, copy (or share, when block is the only successor).
// If this is a subsequent pred, intersect.
Expand Down
11 changes: 7 additions & 4 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,14 @@ bool Compiler::optExtractInitTestIncr(
// If we are rebuilding the loops, we would already have the pre-header block introduced
// the first time, which might be empty if no hoisting has yet occurred. In this case, look a
// little harder for the possible loop initialization statement.
if (initBlock->KindIs(BBJ_ALWAYS) && initBlock->TargetIs(header) && (initBlock->countOfInEdges() == 1) &&
!initBlock->IsFirst() && initBlock->Prev()->bbFallsThrough())
if (initBlock->KindIs(BBJ_ALWAYS) && initBlock->TargetIs(header))
{
initBlock = initBlock->Prev();
phdrStmt = initBlock->firstStmt();
BasicBlock* uniquePred = initBlock->GetUniquePred(this);
if (uniquePred != nullptr)
{
initBlock = uniquePred;
phdrStmt = initBlock->firstStmt();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/rangecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ void RangeCheck::MergeAssertion(BasicBlock* block, GenTree* op, Range* pRange DE
{
GenTreePhiArg* arg = (GenTreePhiArg*)op;
BasicBlock* pred = arg->gtPredBB;
if (pred->bbFallsThrough() && pred->NextIs(block))
if (pred->KindIs(BBJ_COND) && pred->FalseTargetIs(block))
{
assertions = pred->bbAssertionOut;
JITDUMP("Merge assertions from pred " FMT_BB " edge: ", pred->bbNum);
Expand Down
Loading