Slow performance of libc++ std::isinf with integral types

Hi,

While writing a templated function for both floating point and integral types, I noticed that std::isinf with integer input is slow. I reduced the code to the attached benchmark and ran it on macOS 10.11 and Fedora 25 with both clang and GCC. With clang and libc++, using tag dispatch to first check if the type has infinity speeds up the calculation by several times. With either compiler and libstdc++, timings in both cases are fast and nearly identical.

Is there a performance bug in libc++'s std::isinf?

Best,
Steven

macOS 10.11 w/ clang 4.0.0 from homebrew

$ /usr/local/opt/llvm/bin/clang++ -O3 -std=c++1z isinf_libcxx.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.184412
Standard Deviation: 0.0100509
Using std::isinf
Time (s): 0.579823
Standard Deviation: 0.0205093

macOS 10.11 w/ gcc 6.3.0 from homebrew
$ g+±6 -O3 -std=c++1z isinf_libcxx​.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.195277
Standard Deviation: 0.016476
Using std::isinf
Time (s): 0.196114
Standard Deviation: 0.0161064

Fedora 25 w/ clang 3.9.1

$ clang++ -O3 -std=c++1z -stdlib=libc++ isinf_libcxx.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.161073
Standard Deviation: 0.00445347
Using std::isinf
Time (s): 1.40411
Standard Deviation: 0.089235

Fedora 25 w/ clang 3.9.1
$ clang++ -O3 -std=c++1z -stdlib=libstdc++ isinf_libcxx.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.162251
Standard Deviation: 0.00350547
Using std::isinf
Time (s): 0.160011
Standard Deviation: 0.00220987

isinf_libcxx.cpp (3.35 KB)