Skip to content

Commit

Permalink
JIT: Fix loop unscaling computations (#50807)
Browse files Browse the repository at this point in the history
Changes made in #50633 were simply wrong, and lead to division by
infinite values.

Fixes #50743.
  • Loading branch information
AndyAyersMS authored Apr 9, 2021
1 parent 83b8058 commit 950eb6f
Showing 1 changed file with 6 additions and 35 deletions.
41 changes: 6 additions & 35 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,10 @@ void Compiler::optMarkLoopBlocks(BasicBlock* begBlk, BasicBlock* endBlk, bool ex
scale = scale / 2;
}

//
// Set the new weight
//
curBlk->scaleBBWeight(scale);
}
#ifdef DEBUG
if (verbose)
{
printf("\n " FMT_BB "(wt=%s)", curBlk->bbNum, refCntWtd2str(curBlk->getBBWeight(this)));
}
#endif

JITDUMP("\n " FMT_BB "(wt=" FMT_WT ")", curBlk->bbNum, curBlk->getBBWeight(this));
}
}

Expand Down Expand Up @@ -347,41 +340,19 @@ void Compiler::optUnmarkLoopBlocks(BasicBlock* begBlk, BasicBlock* endBlk)
//
if (!curBlk->isMaxBBWeight() && !curBlk->hasProfileWeight())
{
BasicBlock::weight_t weight = curBlk->bbWeight;
BasicBlock::weight_t scale = 1.0f / BB_LOOP_WEIGHT_SCALE;

if (!fgDominate(curBlk, endBlk))
{
weight *= 2;
scale *= 2;
}
else
{
/* Merging of blocks can disturb the Dominates
information (see RAID #46649) */
if (weight < BB_LOOP_WEIGHT_SCALE)
{
weight *= 2;
}
}

// We can overflow here so check for it
if (weight < curBlk->bbWeight)
{
weight = BB_MAX_WEIGHT;
}

assert(curBlk->bbWeight != BB_ZERO_WEIGHT);
BasicBlock::weight_t scale = weight / curBlk->bbWeight;

curBlk->scaleBBWeight(scale);
}

#ifdef DEBUG
if (verbose)
{
printf("\n " FMT_BB "(wt=%s)", curBlk->bbNum, refCntWtd2str(curBlk->getBBWeight(this)));
}
#endif
JITDUMP("\n " FMT_BB "(wt=" FMT_WT ")", curBlk->bbNum, curBlk->getBBWeight(this));
}

/* Stop if we've reached the last block in the loop */

if (curBlk == endBlk)
Expand Down

0 comments on commit 950eb6f

Please sign in to comment.