[PATCH] D86559: [Sema, CodeGen] Allow [[likely]] and [[unlikely]] on labels

Staffan Tjernstrom via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 27 19:06:42 PDT 2020


staffantj added a comment.

In D86559#2242586 <https://reviews.llvm.org/D86559#2242586>, @Mordante wrote:

> if(a)                      // Attribute not allowed on a declaration,
>
>   [[likely]] int i = 5;  // but I can't think about a good use-case
>                          // for this code.
>
> if(a) [[likely]] { // Good allowed on the compound statement
>
>     int i = 5;     // Now i seems to have a purpose
>   ...
>
> }

The use case for this becomes clearer when considering that the attribute that will be used 95% of the time is [[unlikely]]. You may have a constructor that you wish to ask the compiler to please, please, do not inline this, in a particular function, even if the rest of that function is either likely or neutral.

  if (a)
    [[unlikely]] expensive_class q{};

This could be the case if expensive_class held large static members, for instance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86559/new/

https://reviews.llvm.org/D86559



More information about the cfe-commits mailing list