Regression with MSVC 19.16 and later in C++17 mode

Submitted by Christoph Hertzberg @chhtz

Assigned to Nobody

Link to original bugzilla bug (#1765)
Version: 3.3 (current stable)
Operating system: Windows

Description

Reported via mail:

In some of our code using Eigen, we got a 50% increase in runtime
when updating from C++14 to C++17.
We are using Eigen 3.3.7 and MSVC 19.23.

Below is a small example, which gives different assembly on Godbolt.org,
when compiled with

  • MSVC 19.22 /std:c++14 /O2 /Ob2 /GS-
  • MSVC 19.22 /std:c++17 /O2 /Ob2 /GS-

It seems that with C++17, the constructor call is not optimized so the
runtime is much larger. Do you know what is going on?

#include <Eigen/Core>
int main()
{
for (size_t i = 0; i < 0.3e9; ++i)
{
Eigen::Matrix2cd R;
}
return 0;
}

I confirm this, even with /DNDEBUG, but it seems to be a regression from MSVC 19.15 to 19.16 (the constructor of std::complex does not get optimized away):

https://godbolt.org/z/7WDacA

Possible workaround: Add more force-inlines at some places.

Blocking

#1608

Edited by Eigen Bugzilla