[llvm-commits] [llvm] r132613 - in /llvm/trunk: include/llvm/Analysis/BranchProbabilityInfo.h include/llvm/InitializePasses.h lib/Analysis/Analysis.cpp lib/Analysis/BranchProbabilityInfo.cpp lib/Analysis/CMakeLists.txt

Alistair Lynn arplynn at gmail.com
Fri Jun 3 19:29:51 PDT 2011


Hi-

Given that

> +  // Returned value is between 1 and UINT_MAX. Look at BranchProbabilityInfo.cpp
> +  // for details.

Is this function not prone to integer overflow issues?

> +// TODO: This currently hardcodes 80% as a fraction 4/5. We will soon add a
> +// BranchProbability class to encapsulate the fractional probability and
> +// define a few static instances of the class for use as predefined thresholds.
> +bool BranchProbabilityInfo::isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const {
> +  unsigned Sum = 0;
> +  for (succ_iterator I = succ_begin(Src), E = succ_end(Src); I != E; ++I) {
> +    BasicBlock *Succ = *I;
> +    unsigned Weight = getEdgeWeight(Src, Succ);
> +    unsigned PrevSum = Sum;
> +
> +    Sum += Weight;
> +    assert(Sum > PrevSum); (void) PrevSum;
> +  }
> +
> +  return getEdgeWeight(Src, Dst) * 5 > Sum * 4;
> +}

The sum itself is checked for overflow in the assert, but surely there's nothing preventing overflow on the multiplies on the condition at the end?

Alistair





More information about the llvm-commits mailing list