[llvm-commits] [llvm] r136583 - /llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
Eli Friedman
eli.friedman at gmail.com
Sat Jul 30 20:53:14 PDT 2011
On Sat, Jul 30, 2011 at 8:27 PM, Jakub Staszak <jstaszak at apple.com> wrote:
> Author: kuba
> Date: Sat Jul 30 22:27:24 2011
> New Revision: 136583
>
> URL: http://llvm.org/viewvc/llvm-project?rev=136583&view=rev
> Log:
> Add Zero Heurestics to BranchProbabilityInfo. If we compare value to zero we
> decide whether condition is likely to be true this way:
>
> x == 0 -> false
> x < 0 -> false
> x <= 0 -> false
> x != 0 -> true
> x > 0 -> true
> x >= 0 -> true
What's the justification for these heuristics?
> Modified:
> llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
>
> Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=136583&r1=136582&r2=136583&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
> +++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Sat Jul 30 22:27:24 2011
> @@ -11,6 +11,7 @@
> //
> //===----------------------------------------------------------------------===//
>
> +#include "llvm/Constants.h"
> #include "llvm/Instructions.h"
> #include "llvm/Analysis/BranchProbabilityInfo.h"
> #include "llvm/Analysis/LoopInfo.h"
> @@ -72,6 +73,9 @@
> static const uint32_t PH_TAKEN_WEIGHT = 20;
> static const uint32_t PH_NONTAKEN_WEIGHT = 12;
>
> + static const uint32_t ZH_TAKEN_WEIGHT = 20;
> + static const uint32_t ZH_NONTAKEN_WEIGHT = 12;
> +
> // Standard weight value. Used when none of the heuristics set weight for
> // the edge.
> static const uint32_t NORMAL_WEIGHT = 16;
> @@ -125,6 +129,9 @@
> // Loop Branch Heuristics
> bool calcLoopBranchHeuristics(BasicBlock *BB);
>
> + // Zero Heurestics
> + bool calcZeroHeuristics(BasicBlock *BB);
> +
> bool runOnFunction(Function &F);
> };
> } // end anonymous namespace
> @@ -270,6 +277,86 @@
> return true;
> }
>
> +bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) {
> + BranchInst * BI = dyn_cast<BranchInst>(BB->getTerminator());
> + if (!BI || !BI->isConditional())
> + return false;
> +
> + Value *Cond = BI->getCondition();
> + ICmpInst *CI = dyn_cast<ICmpInst>(Cond);
> + if (!CI)
> + return false;
> +
> + Value *LHS = CI->getOperand(0);
> + Value *RHS = CI->getOperand(1);
> +
> + bool hasZero = false;
> + bool lhsZero = false;
> + if (ConstantInt *CI = dyn_cast<ConstantInt>(LHS)) {
> + hasZero = CI->isZero();
> + lhsZero = true;
> + }
The LHS of a compare will never be zero after instcombine runs... so
this check strikes me as unlikely to be useful.
-Eli
More information about the llvm-commits
mailing list