On Sunday, 19 November 2023 22:53:37 CET Jan Hubicka wrote:
> Sadly it is really hard to work out this
> from IPA passes, since we basically care whether the iterator points to
> the same place as the end pointer, which are both passed by reference.
> This is inter-procedural value numbering that is quite out of reach.

I've done a fair share of branching on __builtin_constant_p in 
std::experimental::simd to improve code-gen. It's powerful! But maybe we 
also need the other side of the story to tell the optimizer: "I know you 
can't const-prop everything; but this variable / expression, even if you 
need to put in a lot of effort, the performance difference will be worth 
it."

For std::vector, the remaining capacity could be such a value. The 
functions f() and g() are equivalent (their code-gen isn't https://
compiler-explorer.com/z/r44ejK1qz):

#include <vector>

auto
f()
{
  std::vector<int> x;
  x.reserve(10);
  for (int i = 0; i < 10; ++i)
    x.push_back(0);
  return x;
}

auto
g()
{ return std::vector<int>(10, 0); }

-- 
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Center for Heavy Ion Research               https://gsi.de
 std::simd
──────────────────────────────────────────────────────────────────────────

Reply via email to