https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100021
Bug ID: 100021
Summary: [9/10/11 Regression] std::clamp unprofitable
vectorization on -march=nehalem/.../broadwell
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: nok.raven at gmail dot com
Target Milestone: ---
//#include <algorithm>
namespace std
{
template<typename _Tp>
constexpr const _Tp&
clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi)
{
return (__val < __lo) ? __lo : (__hi < __val) ? __hi : __val;
}
}
int foo(int x, int y) {
return std::clamp(x - y, -1, 1);
}
https://godbolt.org/z/6534c1ff1 either GCC makes unprofitable vectorization or
LLVM MCA calculation is wrong.
Affected targets are
-march=nehalem/westmere/sandybridge/ivybridge/haswell/broadwell.
I do not know why it is vectorized on -O2 in the first place; could not find a
switch which triggers it, and doing -O1 + everything -O2 supposed to be
enabling does not reproduce the -O2 behavior.