[PATCH] D20116: Add speculatable function attribute

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 22 16:28:54 PDT 2017


hfinkel added a comment.

In https://reviews.llvm.org/D20116#708191, @arsenm wrote:

> In https://reviews.llvm.org/D20116#708174, @mehdi_amini wrote:
>
> > In https://reviews.llvm.org/D20116#708109, @hfinkel wrote:
> >
> > > In https://reviews.llvm.org/D20116#708076, @mehdi_amini wrote:
> > >
> > > > That troubles (and worries) me as well.
> > >
> > >
> > > Why?
> >
> >
> > Irrational fear? ;-)
> >  It seems unusual, and I'm cautious about introducing unusual properties in the compiler in general, it makes it harder to reason about "stuff" when there aren't "simple" rules to guide the logic.
> >  Are there existing other cases of UB induced by unreachable/dead code?
>
>
> I suppose it's the same as speculating a load from a pointer marked as dereferencable that isn't really, which is already done


My understanding of what gives people pause is that:

  if (p != nullptr)
    something();
  
  if (false)
    foo(p /*nonnull*/) /* speculatable */

depending on the pass ordering, we might end up hoisting the call to foo and then using the nonnull assumption to simplify the if condition (even though that call is dynamically dead). We might not, however (and probably won't because we pretty eagerly remove dead code).

The thing to realize about speculatable is that it promotes all argument restrictions to properties of the argument values themselves. This might certainly seem surprising.


https://reviews.llvm.org/D20116





More information about the llvm-commits mailing list