https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94413
Bug ID: 94413
Summary: auto-vectorization of isfinite raises FP exception
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: kretz at kde dot org
Target Milestone: ---
Target: x86_64-*-*, i?86-*-*
Test case (`-O3`, cf. https://godbolt.org/z/jdfv3r):
#include <cfenv>
#include <cmath>
#include <limits>
using f4 [[gnu::vector_size(16)]] = float;
f4 isfinite(f4 x) {
f4 r = {};
for (int i = 0; i < 4; ++i) r[i] = std::isfinite(x[i]) ? 1.f : 0.f;
return r;
}
using L = std::numeric_limits<float>;
f4 test = {1, 2, 3, L::quiet_NaN()};
int main() {
std::feclearexcept(FE_ALL_EXCEPT);
test = isfinite(test);
if (std::fetestexcept(FE_ALL_EXCEPT) != 0) __builtin_abort();
return 0;
}
This translates to `fabs(test)<=FLT_MAX` but incorrectly using a signaling
compare instruction.
Alterative vectorization of isfinite(x):
* interpret x as int vector
* return inf > x & inf
This works because if all exponent bits of x are set, x is either inf or NaN
(i.e. not finite).