c++floating-pointicccompiler-flagsicx

Fast floating point model broken on next-generation intel compiler


Description

I'm trying to switch over from using the classic intel compiler from the Intel OneAPI toolkit to the next-generation DPC/C++ compiler, but the default behaviour for handling floating point operations appears broken or different, in that comparison with infinity always evaluates to false in fast floating point modes. The above is both a compiler warning and the behaviour I now experience with ICX, but not a behaviour experienced with the classic compiler (for the same minimal set of compiler flags used).

Minimally reproducible example

#include <iostream>
#include <cmath>

int main()
{
    double a = 1.0/0.0;
    if (std::isinf(a))
        std::cout << "is infinite";
    else
        std::cout << "is not infinite;";
}

Compiler Flags: -O3 -Wall -fp-model=fast

ICC 2021.5.0 Output: is infinite (also tested on several older versions)

ICX 2022.0.0 Output: is not infinite (also tested on 2022.0.1)

Live demo on compiler-explorer: https://godbolt.org/z/vzeYj1Wa3

By default -fp-model=fast is enabled on both compilers. If I manually specify -fp-model=precise I can recover the behaviour but not the performance.

Does anyone know of a potential solution to both maintain the previous behaviour & performance of the fast floating point model using the next-gen compiler?


Solution

  • If you add -fp-speculation=safe to -fp-model=fast, you will still get the warning that you shouldn't use -fp-model=fast if you want to check for infinity, but the condition will evaluate correctly: godbolt.

    In the Intel Porting Guide for ICC Users to DPCPP or ICX it is stated that:

    FP Strictness: Nothing stricter than the default is supported. There is no support for -fp-model strict, -fp-speculation=safe, #pragma fenv_access, etc. Implementing support for these is a work-in-progress in the open source community.

    Even though it works for the current version of the tested compiler (icx 2022.0.0), there is a discrepancy: either the documentation is outdated (more probable), or this feature is working by accident (less probable).