<p><br>
On Dec 27, 2011 5:32 AM, "Duncan Sands" <<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>> wrote:<br>
><br>
> Hi Chandler,<br>
><br>
> > Make the unreachable probability much much heavier. The previous<br>
> > probability wouldn't be considered "hot" in some weird loop structures<br>
> > or other compounding probability patterns. This makes it much harder to<br>
> > confuse, but isn't really a principled fix. I'd actually like it if we<br>
> > could model a zero probability, as it would make this much easier to<br>
> > reason about. Suggestions for how to do this better are welcome.<br>
><br>
> a call to a function that only throws an exception will usually be followed<br>
> by unreachable.  Would giving unreachable zero probability mean that throwing<br>
> the exception is considered to occur with probability zero?  While throwing<br>
> exceptions is fairly rare, it does happen.</p>
<p>I think to handle this well the probability analysis would need to learn about exceptions and throwing so it can differentiate between abort and throw.</p>
<p>I suspect there are other places where we compute poor probabilities in the face of exceptions.</p>
<p>Still, treating probably exceptional code paths as having a probability that *approaches* zero (as BPI is never used to prove reachability) seems not entirely unreasonable-it means we will optimize the non-throwing path over the throwing path at any expense. That's the same trade off as zero-cost exceptions? Anyways, I'm not saying it's the right long term model, suggestions here are very welcome.</p>

<p>><br>
> Ciao, Duncan.<br>
><br>
> ><br>
> > Modified:<br>
> >      llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp<br>
> >      llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll<br>
> ><br>
> > Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=147142&r1=147141&r2=147142&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=147142&r1=147141&r2=147142&view=diff</a><br>

> > ==============================================================================<br>
> > --- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)<br>
> > +++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Thu Dec 22 03:26:37 2011<br>
> > @@ -65,8 +65,9 @@<br>
> >   ///<br>
> >   /// This is the weight for a branch not being taken toward a block that<br>
> >   /// terminates (eventually) in unreachable. Such a branch is essentially never<br>
> > -/// taken.<br>
> > -static const uint32_t UR_NONTAKEN_WEIGHT = 1023;<br>
> > +/// taken. Set the weight to an absurdly high value so that nested loops don't<br>
> > +/// easily subsume it.<br>
> > +static const uint32_t UR_NONTAKEN_WEIGHT = 1024*1024 - 1;<br>
> ><br>
> >   static const uint32_t PH_TAKEN_WEIGHT = 20;<br>
> >   static const uint32_t PH_NONTAKEN_WEIGHT = 12;<br>
> ><br>
> > Modified: llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll?rev=147142&r1=147141&r2=147142&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll?rev=147142&r1=147141&r2=147142&view=diff</a><br>

> > ==============================================================================<br>
> > --- llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll (original)<br>
> > +++ llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll Thu Dec 22 03:26:37 2011<br>
> > @@ -8,8 +8,8 @@<br>
> >   entry:<br>
> >     %cond = icmp eq i32 %a, 42<br>
> >     br i1 %cond, label %exit, label %abort<br>
> > -; CHECK: edge entry ->  exit probability is 1023 / 1024<br>
> > -; CHECK: edge entry ->  abort probability is 1 / 1024<br>
> > +; CHECK: edge entry ->  exit probability is 1048575 / 1048576<br>
> > +; CHECK: edge entry ->  abort probability is 1 / 1048576<br>
> ><br>
> >   abort:<br>
> >     call void @abort() noreturn<br>
> > @@ -26,11 +26,11 @@<br>
> >                                 i32 2, label %case_b<br>
> >                                 i32 3, label %case_c<br>
> >                                 i32 4, label %case_d]<br>
> > -; CHECK: edge entry ->  exit probability is 1023 / 1027<br>
> > -; CHECK: edge entry ->  case_a probability is 1 / 1027<br>
> > -; CHECK: edge entry ->  case_b probability is 1 / 1027<br>
> > -; CHECK: edge entry ->  case_c probability is 1 / 1027<br>
> > -; CHECK: edge entry ->  case_d probability is 1 / 1027<br>
> > +; CHECK: edge entry ->  exit probability is 1048575 / 1048579<br>
> > +; CHECK: edge entry ->  case_a probability is 1 / 1048579<br>
> > +; CHECK: edge entry ->  case_b probability is 1 / 1048579<br>
> > +; CHECK: edge entry ->  case_c probability is 1 / 1048579<br>
> > +; CHECK: edge entry ->  case_d probability is 1 / 1048579<br>
> ><br>
> >   case_a:<br>
> >     br label %case_b<br>
> > @@ -55,8 +55,8 @@<br>
> >   entry:<br>
> >     %cond1 = icmp eq i32 %a, 42<br>
> >     br i1 %cond1, label %exit, label %dom<br>
> > -; CHECK: edge entry ->  exit probability is 1023 / 1024<br>
> > -; CHECK: edge entry ->  dom probability is 1 / 1024<br>
> > +; CHECK: edge entry ->  exit probability is 1048575 / 1048576<br>
> > +; CHECK: edge entry ->  dom probability is 1 / 1048576<br>
> ><br>
> >   dom:<br>
> >     %cond2 = icmp ult i32 %a, 42<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > llvm-commits mailing list<br>
> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</p>