[PATCH] annotate vector::_M_default_append fo better codegen (PR 83229)

François Dumont frs.dumont@gmail.com
Sun Dec 10 21:13:00 GMT 2017


On 06/12/2017 04:44, Martin Sebor wrote:
>
> Since it's possible that there may be other opportunities for
> similar annotation in libstdc++, if changes along these lines
> become more than isolated instances, it may be worth considering
> adding a macro to make the conditions more readable.  E.g., to
> follow the example of __glibcxx_assert, something like:
>
>   #define __glibcxx_assume(expr) \
>     ((expr) ? (void)0 : __builtin_unreachable())
>

Or perhaps do something like that:

@@ -485,7 +485,9 @@ namespace std
  #if defined(_GLIBCXX_ASSERTIONS)
  # define __glibcxx_assert(_Condition) __glibcxx_assert_impl(_Condition)
  #else
-# define __glibcxx_assert(_Condition)
+# define __glibcxx_assert(_Condition)                                  \
+    ((_Condition) ? (void)0 : __builtin_unreachable())
  #endif

So that assertions are automatically transform into optimizer hints on 
release builds.

As the problem is that gcc doesn't remember anything about pointers then 
those assertions at the begining of the method could acheive the same 
result:

__glibcxx_assert(this->_M_impl._M_start <= this->_M_impl._M_finish);
__glibcxx_assert(this->_M_impl._M_finish < this->_M_impl._M_end_of_storage);



More information about the Libstdc++ mailing list