Skip to content

Commit dfa5c00

Browse files
committed
JIT: Fix some cases using BasicBlock::bbFallsThrough
`bbFallsThrough` still returns true for `BBJ_COND`; we have a couple of places using it as a "control flows from prev block" check, which is wrong after dotnet#97488.
1 parent b76ef7f commit dfa5c00

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

src/coreclr/jit/block.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,13 @@ Statement* BasicBlock::FirstNonPhiDefOrCatchArgStore() const
11231123
return stmt;
11241124
}
11251125

1126-
/*****************************************************************************
1127-
*
1128-
* Can a BasicBlock be inserted after this without altering the flowgraph
1129-
*/
1130-
1126+
//------------------------------------------------------------------------
1127+
// bbFallsThrough: Check if inserting a BasicBlock after this one will alter
1128+
// the flowgraph.
1129+
//
1130+
// Returns:
1131+
// True if so.
1132+
//
11311133
bool BasicBlock::bbFallsThrough() const
11321134
{
11331135
switch (bbKind)

src/coreclr/jit/morph.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13869,7 +13869,7 @@ void Compiler::fgMorphBlock(BasicBlock* block)
1386913869
// Yes, pred assertions are available.
1387013870
// If the pred is (a non-degenerate) BBJ_COND, fetch the appropriate out set.
1387113871
//
13872-
ASSERT_TP assertionsOut = pred->bbAssertionOut;
13872+
ASSERT_TP assertionsOut;
1387313873
const bool useCondAssertions = pred->KindIs(BBJ_COND) && (pred->NumSucc() == 2);
1387413874

1387513875
if (useCondAssertions)
@@ -13886,6 +13886,10 @@ void Compiler::fgMorphBlock(BasicBlock* block)
1388613886
assertionsOut = pred->bbAssertionOutIfFalse;
1388713887
}
1388813888
}
13889+
else
13890+
{
13891+
assertionsOut = pred->bbAssertionOut;
13892+
}
1388913893

1389013894
// If this is the first pred, copy (or share, when block is the only successor).
1389113895
// If this is a subsequent pred, intersect.

src/coreclr/jit/optimizer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,14 @@ bool Compiler::optExtractInitTestIncr(
463463
// If we are rebuilding the loops, we would already have the pre-header block introduced
464464
// the first time, which might be empty if no hoisting has yet occurred. In this case, look a
465465
// little harder for the possible loop initialization statement.
466-
if (initBlock->KindIs(BBJ_ALWAYS) && initBlock->TargetIs(header) && (initBlock->countOfInEdges() == 1) &&
467-
!initBlock->IsFirst() && initBlock->Prev()->bbFallsThrough())
466+
if (initBlock->KindIs(BBJ_ALWAYS) && initBlock->TargetIs(header))
468467
{
469-
initBlock = initBlock->Prev();
470-
phdrStmt = initBlock->firstStmt();
468+
BasicBlock* uniquePred = initBlock->GetUniquePred(this);
469+
if (uniquePred != nullptr)
470+
{
471+
initBlock = uniquePred;
472+
phdrStmt = initBlock->firstStmt();
473+
}
471474
}
472475
}
473476

src/coreclr/jit/rangecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ void RangeCheck::MergeAssertion(BasicBlock* block, GenTree* op, Range* pRange DE
935935
{
936936
GenTreePhiArg* arg = (GenTreePhiArg*)op;
937937
BasicBlock* pred = arg->gtPredBB;
938-
if (pred->bbFallsThrough() && pred->NextIs(block))
938+
if (pred->KindIs(BBJ_COND) && pred->FalseTargetIs(block))
939939
{
940940
assertions = pred->bbAssertionOut;
941941
JITDUMP("Merge assertions from pred " FMT_BB " edge: ", pred->bbNum);

0 commit comments

Comments
 (0)