Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

__builtin_expect() chokes on dfp754

Sebastian_Freundt
808 Views

As defined in IEEE-754 comparisons with NAN should always yield false, this works:


 

#define __STDC_WANT_DEC_FP__
#include <dfp754.h>

if (0.4dd > nand64("")) {
        return 1;
}
return 0;

 

Now, __builtin_expect is to give advice to the compiler about the outcome of a boolean expression, it shouldn't change the code path at all, however it does:

#define __STDC_WANT_DEC_FP__
#include <dfp754.h>

if (__builtin_expect(0.4dd > nand64(""), 0)) {
        return 1;
}
return 0;

 

This snippet compiled with icc (ICC) 17.0.4 20170411 will now return 1.

 

0 Kudos
6 Replies
Viet_H_Intel
Moderator
808 Views

Hi Sebastian,

I couldn't reproduce it at my end. It returned 0 in both cases. Can you give us you test case along with your command line options and the OS you run it on?

Regards,

Viet Hoang

0 Kudos
Sebastian_Freundt
808 Views
$ icc -std=gnu11 -fast -x c - -Wall -D__STDC_WANT_DEC_FP__ <<EOF
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dfp754.h>
#include <math.h>
int
main(int argc, char *argv[])
{
if (__builtin_expect(0.4 > nand64(""), 0)) {
return 1;
}
return 0;
}
EOF
$ ./a.out || echo "broken"
broken
$

from /etc/os-release:
NAME=openSUSE
VERSION="13.1 (Bottle)"
VERSION_ID="13.1"
PRETTY_NAME="openSUSE 13.1 (Bottle) (x86_64)"
ID=opensuse
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:opensuse:13.1"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://opensuse.org/"
ID_LIKE="suse"
 

0 Kudos
Sebastian_Freundt
808 Views

Now that I've had some more time to play with it, I found out, it's the -ipo bit (implied by -fast).

So icc -O3 works, icc -O0 -ipo, icc -O1 -ipo do too.  Whereas icc -O2 -ipo and icc -O3 -ipo do not work.


 

0 Kudos
Viet_H_Intel
Moderator
808 Views

It looks like a bug to me. Can you please submit a ticket at https://supporttickets.intel.com/ ?

Regards,

Viet Hoang

0 Kudos
Sebastian_Freundt
808 Views

Certainly, thanks for confirming.

0 Kudos
Sebastian_Freundt
808 Views
Just to let you know, icc 18.0.0 20170811 still shows this issue.
0 Kudos
Reply