[llvm-commits] [llvm] r147142 - in /llvm/trunk: lib/Analysis/BranchProbabilityInfo.cpp test/Analysis/BranchProbabilityInfo/noreturn.ll

Chandler Carruth chandlerc at google.com
Tue Dec 27 03:02:12 PST 2011


On Dec 27, 2011 5:32 AM, "Duncan Sands" <baldrick at free.fr> wrote:
>
> Hi Chandler,
>
> > Make the unreachable probability much much heavier. The previous
> > probability wouldn't be considered "hot" in some weird loop structures
> > or other compounding probability patterns. This makes it much harder to
> > confuse, but isn't really a principled fix. I'd actually like it if we
> > could model a zero probability, as it would make this much easier to
> > reason about. Suggestions for how to do this better are welcome.
>
> a call to a function that only throws an exception will usually be
followed
> by unreachable.  Would giving unreachable zero probability mean that
throwing
> the exception is considered to occur with probability zero?  While
throwing
> exceptions is fairly rare, it does happen.

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.

I suspect there are other places where we compute poor probabilities in the
face of exceptions.

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.

>
> Ciao, Duncan.
>
> >
> > Modified:
> >      llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
> >      llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll
> >
> > Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=147142&r1=147141&r2=147142&view=diff
> >
==============================================================================
> > --- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
> > +++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Thu Dec 22
03:26:37 2011
> > @@ -65,8 +65,9 @@
> >   ///
> >   /// This is the weight for a branch not being taken toward a block
that
> >   /// terminates (eventually) in unreachable. Such a branch is
essentially never
> > -/// taken.
> > -static const uint32_t UR_NONTAKEN_WEIGHT = 1023;
> > +/// taken. Set the weight to an absurdly high value so that nested
loops don't
> > +/// easily subsume it.
> > +static const uint32_t UR_NONTAKEN_WEIGHT = 1024*1024 - 1;
> >
> >   static const uint32_t PH_TAKEN_WEIGHT = 20;
> >   static const uint32_t PH_NONTAKEN_WEIGHT = 12;
> >
> > Modified: llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll
> > URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll?rev=147142&r1=147141&r2=147142&view=diff
> >
==============================================================================
> > --- llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll
(original)
> > +++ llvm/trunk/test/Analysis/BranchProbabilityInfo/noreturn.ll Thu Dec
22 03:26:37 2011
> > @@ -8,8 +8,8 @@
> >   entry:
> >     %cond = icmp eq i32 %a, 42
> >     br i1 %cond, label %exit, label %abort
> > -; CHECK: edge entry ->  exit probability is 1023 / 1024
> > -; CHECK: edge entry ->  abort probability is 1 / 1024
> > +; CHECK: edge entry ->  exit probability is 1048575 / 1048576
> > +; CHECK: edge entry ->  abort probability is 1 / 1048576
> >
> >   abort:
> >     call void @abort() noreturn
> > @@ -26,11 +26,11 @@
> >                                 i32 2, label %case_b
> >                                 i32 3, label %case_c
> >                                 i32 4, label %case_d]
> > -; CHECK: edge entry ->  exit probability is 1023 / 1027
> > -; CHECK: edge entry ->  case_a probability is 1 / 1027
> > -; CHECK: edge entry ->  case_b probability is 1 / 1027
> > -; CHECK: edge entry ->  case_c probability is 1 / 1027
> > -; CHECK: edge entry ->  case_d probability is 1 / 1027
> > +; CHECK: edge entry ->  exit probability is 1048575 / 1048579
> > +; CHECK: edge entry ->  case_a probability is 1 / 1048579
> > +; CHECK: edge entry ->  case_b probability is 1 / 1048579
> > +; CHECK: edge entry ->  case_c probability is 1 / 1048579
> > +; CHECK: edge entry ->  case_d probability is 1 / 1048579
> >
> >   case_a:
> >     br label %case_b
> > @@ -55,8 +55,8 @@
> >   entry:
> >     %cond1 = icmp eq i32 %a, 42
> >     br i1 %cond1, label %exit, label %dom
> > -; CHECK: edge entry ->  exit probability is 1023 / 1024
> > -; CHECK: edge entry ->  dom probability is 1 / 1024
> > +; CHECK: edge entry ->  exit probability is 1048575 / 1048576
> > +; CHECK: edge entry ->  dom probability is 1 / 1048576
> >
> >   dom:
> >     %cond2 = icmp ult i32 %a, 42
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111227/b2657a30/attachment.html>


More information about the llvm-commits mailing list