diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index 0c21487300836..e71566da1f76a 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -142,7 +142,7 @@ FlowEdge* Compiler::BlockPredsWithEH(BasicBlock* blk) { if (bbInExnFlowRegions(tryIndex, bb) && !bb->isBBCallFinallyPairTail()) { - res = new (this, CMK_FlowEdge) FlowEdge(bb, res); + res = new (this, CMK_FlowEdge) FlowEdge(bb, blk, res); #if MEASURE_BLOCK_SIZE genFlowNodeCnt += 1; @@ -164,7 +164,7 @@ FlowEdge* Compiler::BlockPredsWithEH(BasicBlock* blk) for (BasicBlock* filterBlk = enclosingDsc->ebdFilter; filterBlk != enclosingDsc->ebdHndBeg; filterBlk = filterBlk->Next()) { - res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, res); + res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, blk, res); assert(filterBlk->VisitEHEnclosedHandlerSecondPassSuccs(this, [blk](BasicBlock* succ) { return succ == blk ? BasicBlockVisit::Abort : BasicBlockVisit::Continue; @@ -239,7 +239,7 @@ FlowEdge* Compiler::BlockDominancePreds(BasicBlock* blk) for (BasicBlock* filterBlk = enclosingDsc->ebdFilter; filterBlk != enclosingDsc->ebdHndBeg; filterBlk = filterBlk->Next()) { - res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, res); + res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, blk, res); assert(filterBlk->VisitEHEnclosedHandlerSecondPassSuccs(this, [blk](BasicBlock* succ) { return succ == blk ? BasicBlockVisit::Abort : BasicBlockVisit::Continue; diff --git a/src/coreclr/jit/block.h b/src/coreclr/jit/block.h index 3556087253edb..d434ae8a92b01 100644 --- a/src/coreclr/jit/block.h +++ b/src/coreclr/jit/block.h @@ -2059,6 +2059,9 @@ struct FlowEdge // The source of the control flow BasicBlock* m_sourceBlock; + // The destination of the control flow + BasicBlock* m_destBlock; + // Edge weights weight_t m_edgeWeightMin; weight_t m_edgeWeightMax; @@ -2074,9 +2077,10 @@ struct FlowEdge bool m_likelihoodSet; public: - FlowEdge(BasicBlock* block, FlowEdge* rest) + FlowEdge(BasicBlock* sourceBlock, BasicBlock* destBlock, FlowEdge* rest) : m_nextPredEdge(rest) - , m_sourceBlock(block) + , m_sourceBlock(sourceBlock) + , m_destBlock(destBlock) , m_edgeWeightMin(0) , m_edgeWeightMax(0) , m_likelihood(0) @@ -2102,14 +2106,28 @@ struct FlowEdge BasicBlock* getSourceBlock() const { + assert(m_sourceBlock != nullptr); return m_sourceBlock; } void setSourceBlock(BasicBlock* newBlock) { + assert(newBlock != nullptr); m_sourceBlock = newBlock; } + BasicBlock* getDestinationBlock() const + { + assert(m_destBlock != nullptr); + return m_destBlock; + } + + void setDestinationBlock(BasicBlock* newBlock) + { + assert(newBlock != nullptr); + m_destBlock = newBlock; + } + weight_t edgeWeightMin() const { return m_edgeWeightMin; diff --git a/src/coreclr/jit/fgdiagnostic.cpp b/src/coreclr/jit/fgdiagnostic.cpp index ed3f4252bed5a..3cdb70930e63c 100644 --- a/src/coreclr/jit/fgdiagnostic.cpp +++ b/src/coreclr/jit/fgdiagnostic.cpp @@ -2683,6 +2683,10 @@ unsigned BBPredsChecker::CheckBBPreds(BasicBlock* block, unsigned curTraversalSt } assert(CheckJump(blockPred, block)); + + // Make sure the pred edge's destination block is correct + // + assert(pred->getDestinationBlock() == block); } // Make sure preds are in increasing BBnum order diff --git a/src/coreclr/jit/fgflow.cpp b/src/coreclr/jit/fgflow.cpp index e384bc6155890..3b6afa82bed54 100644 --- a/src/coreclr/jit/fgflow.cpp +++ b/src/coreclr/jit/fgflow.cpp @@ -204,7 +204,7 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE // Create new edge in the list in the correct ordered location. // - flow = new (this, CMK_FlowEdge) FlowEdge(blockPred, *listp); + flow = new (this, CMK_FlowEdge) FlowEdge(blockPred, block, *listp); flow->incrementDupCount(); *listp = flow; diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 05eb5c7d3b9fb..bcb0bc90d071c 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -196,7 +196,7 @@ void Compiler::optScaleLoopBlocks(BasicBlock* begBlk, BasicBlock* endBlk) // Is this a back edge? if (predBlock->bbNum >= begBlk->bbNum) { - backedgeList = new (this, CMK_FlowEdge) FlowEdge(predBlock, backedgeList); + backedgeList = new (this, CMK_FlowEdge) FlowEdge(predBlock, begBlk, backedgeList); #if MEASURE_BLOCK_SIZE genFlowNodeCnt += 1;