<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div>-Kuba</div></span>
</div>
<br><div><div>On Jul 30, 2011, at 8:53 PM, Eli Friedman wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Sat, Jul 30, 2011 at 8:27 PM, Jakub Staszak <<a href="mailto:jstaszak@apple.com">jstaszak@apple.com</a>> wrote:<br><blockquote type="cite">Author: kuba<br></blockquote><blockquote type="cite">Date: Sat Jul 30 22:27:24 2011<br></blockquote><blockquote type="cite">New Revision: 136583<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=136583&view=rev">http://llvm.org/viewvc/llvm-project?rev=136583&view=rev</a><br></blockquote><blockquote type="cite">Log:<br></blockquote><blockquote type="cite">Add Zero Heurestics to BranchProbabilityInfo. If we compare value to zero we<br></blockquote><blockquote type="cite">decide whether condition is likely to be true this way:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">x == 0  ->  false<br></blockquote><blockquote type="cite">x <  0  ->  false<br></blockquote><blockquote type="cite">x <= 0  ->  false<br></blockquote><blockquote type="cite">x != 0  ->  true<br></blockquote><blockquote type="cite">x >  0  ->  true<br></blockquote><blockquote type="cite">x >= 0  ->  true<br></blockquote><br>What's the justification for these heuristics?<br></div></blockquote><div><br></div><div>It is one of the heuristics proposed in the paper "Static Branch Frequency and Program Profile Analysis". The other heuristics we have right now were also proposed there.</div><br><blockquote type="cite"><div><blockquote type="cite">Modified:<br></blockquote><blockquote type="cite">   llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp<br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=136583&r1=136582&r2=136583&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=136583&r1=136582&r2=136583&view=diff</a><br></blockquote><blockquote type="cite">==============================================================================<br></blockquote><blockquote type="cite">--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)<br></blockquote><blockquote type="cite">+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Sat Jul 30 22:27:24 2011<br></blockquote><blockquote type="cite">@@ -11,6 +11,7 @@<br></blockquote><blockquote type="cite"> //<br></blockquote><blockquote type="cite"> //===----------------------------------------------------------------------===//<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+#include "llvm/Constants.h"<br></blockquote><blockquote type="cite"> #include "llvm/Instructions.h"<br></blockquote><blockquote type="cite"> #include "llvm/Analysis/BranchProbabilityInfo.h"<br></blockquote><blockquote type="cite"> #include "llvm/Analysis/LoopInfo.h"<br></blockquote><blockquote type="cite">@@ -72,6 +73,9 @@<br></blockquote><blockquote type="cite">  static const uint32_t PH_TAKEN_WEIGHT = 20;<br></blockquote><blockquote type="cite">  static const uint32_t PH_NONTAKEN_WEIGHT = 12;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+  static const uint32_t ZH_TAKEN_WEIGHT = 20;<br></blockquote><blockquote type="cite">+  static const uint32_t ZH_NONTAKEN_WEIGHT = 12;<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">  // Standard weight value. Used when none of the heuristics set weight for<br></blockquote><blockquote type="cite">  // the edge.<br></blockquote><blockquote type="cite">  static const uint32_t NORMAL_WEIGHT = 16;<br></blockquote><blockquote type="cite">@@ -125,6 +129,9 @@<br></blockquote><blockquote type="cite">  // Loop Branch Heuristics<br></blockquote><blockquote type="cite">  bool calcLoopBranchHeuristics(BasicBlock *BB);<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+  // Zero Heurestics<br></blockquote><blockquote type="cite">+  bool calcZeroHeuristics(BasicBlock *BB);<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">  bool runOnFunction(Function &F);<br></blockquote><blockquote type="cite"> };<br></blockquote><blockquote type="cite"> } // end anonymous namespace<br></blockquote><blockquote type="cite">@@ -270,6 +277,86 @@<br></blockquote><blockquote type="cite">  return true;<br></blockquote><blockquote type="cite"> }<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) {<br></blockquote><blockquote type="cite">+  BranchInst * BI = dyn_cast<BranchInst>(BB->getTerminator());<br></blockquote><blockquote type="cite">+  if (!BI || !BI->isConditional())<br></blockquote><blockquote type="cite">+    return false;<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  Value *Cond = BI->getCondition();<br></blockquote><blockquote type="cite">+  ICmpInst *CI = dyn_cast<ICmpInst>(Cond);<br></blockquote><blockquote type="cite">+  if (!CI)<br></blockquote><blockquote type="cite">+    return false;<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  Value *LHS = CI->getOperand(0);<br></blockquote><blockquote type="cite">+  Value *RHS = CI->getOperand(1);<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  bool hasZero = false;<br></blockquote><blockquote type="cite">+  bool lhsZero = false;<br></blockquote><blockquote type="cite">+  if (ConstantInt *CI = dyn_cast<ConstantInt>(LHS)) {<br></blockquote><blockquote type="cite">+    hasZero = CI->isZero();<br></blockquote><blockquote type="cite">+    lhsZero = true;<br></blockquote><blockquote type="cite">+  }<br></blockquote><br>The LHS of a compare will never be zero after instcombine runs... so<br>this check strikes me as unlikely to be useful.<br><br></div></blockquote>So instcombiner always moves zero (or constants in general) to RHS?<br><br><blockquote type="cite"><div>-Eli<br></div></blockquote><br></div><div>- Kuba</div><br></body></html>