https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80093
Bug ID: 80093
Summary: missed optimization opportunity with
std::uniform_int_distribution
Product: gcc
Version: 7.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: trashyankes at wp dot pl
Target Milestone: ---
We have two functions:
```
#include <random>
int foo (std::mt19937* x)
{
for (auto i = 0; i < 1'000'000'000; ++i)
{
std::uniform_int_distribution<int> y(0, 99);
volatile auto r = y(*x);
}
}
int bar (std::mt19937* x)
{
std::uniform_int_distribution<int> y(0, 99);
for (auto i = 0; i < 1'000'000'000; ++i)
{
volatile auto r = y(*x);
}
}
```
https://godbolt.org/g/kiFC2a
Result is that `foo` is 10 time smaller than `bar`, as
`std::uniform_int_distribution` have only two fields that do not leak
references to some external code (at least I do not find that looking at src
code) and do not modify its values, this should behave same.
This behave like that from 4.8.1, before
`std::uniform_int_distribution::operator()` was not inlined and both functions
look same.