Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*

Floating Point gets miscompiled.

Mysticial
Beginner
194 Views

Compiler: Intel(R) oneAPI DPC++/C++ Compiler 2025.0.0 (2025.0.0.20241008)

OS: Windows (via Visual Studio 17.11.5)

 

The following code is incorrectly compiled:

 

#include <iostream>
using std::cout;
using std::endl;

#define NO_INLINE       __declspec(noinline)
#define FORCE_INLINE    inline __forceinline

class Object{
public:
    FORCE_INLINE Object(uint64_t x) : Object(nullptr, (uint32_t)x, (double)(uint32_t)(x >> 32) * 4294967296.) {}
    FORCE_INLINE Object(void*, double L, double H){
        double r0;

        r0 = (double)(L + H);
        hi = r0;

        r0 = (double)(r0 - H);
        lo = (double)(L - r0);
    }

    double lo;
    double hi;
};

NO_INLINE Object func(const Object& a){
    return a;
}

NO_INLINE void test_function(uint32_t k){
    uint64_t stop = (uint64_t)1 << k;
    stop /= 4;
    for (uint64_t c = 0; c < stop; c++){
        Object obj = func(c);
        cout << "c = " << c << ": obj = " << obj.hi << endl;
    }
}

int main(){
    test_function(9);
}

 

Compiler Flags:

 

/GS /W3 /QxAVX /Gy /Zc:wchar_t /Zi /O3 /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "__INTEL_LLVM_COMPILER=20250000" /D "_UNICODE" /D "UNICODE" /Qipo /Zc:forScope /Oi /MD /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\ICX2025 Miscompile 1.pch" 

 

Expected Output:

 

c = 0: obj = 0
c = 1: obj = 1
c = 2: obj = 2
c = 3: obj = 3
c = 4: obj = 4
c = 5: obj = 5
c = 6: obj = 6
c = 7: obj = 7
...

 

Actual Output:

 

c = 0: obj = 0
c = 1: obj = 6.95222e-310
c = 2: obj = 8.04776e-312
c = 3: obj = 8.04776e-312
c = 4: obj = 6.1857e-321
c = 5: obj = 1.7407e-315
c = 6: obj = 1.26481e-321
c = 7: obj = 3.95253e-323
...

 

0 Kudos
1 Reply
yzh_intel
Moderator
98 Views

Hi, I reproduced the issue, it seems that the compiler performed some incorrect optimization. I have escalated the issue to compiler engineering team. Thanks for reporting issues to us.

Meanwhile, can you try to set the optimization level to /O2 instead of /O3? In my testing, the case passes with /O2.


0 Kudos
Reply