[Bug tree-optimization/84407] New: incorrect constant propagation with -frounding-math
mikulas at artax dot karlin.mff.cuni.cz
gcc-bugzilla@gcc.gnu.org
Thu Feb 15 13:56:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84407
Bug ID: 84407
Summary: incorrect constant propagation with -frounding-math
Product: gcc
Version: 7.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: mikulas at artax dot karlin.mff.cuni.cz
Target Milestone: ---
With -frounding-math, gcc should not do optimizations if the result is affected
by the rounding mode. But it still does some of them - it propagates constants
across integer-to-float conversions, despite the fact that these conversions
are affected by the rounding mode.
When this program is compiled with -O2 -frounding-math (on x86-64 linux), you
get:
7fffffffffffffff -> 8000000000000000
7fffffffffffffff -> 8000000000000000
7fffffffffffffff -> 8000000000000000
7fffffffffffffff -> 8000000000000000
With -O0 -frounding-math, you get:
7fffffffffffffff -> 8000000000000000
7fffffffffffffff -> 7ffffffffffffc00
7fffffffffffffff -> 8000000000000000
7fffffffffffffff -> 7ffffffffffffc00
#include <stdio.h>
#include <inttypes.h>
#include <fenv.h>
void print_val(uint64_t x)
{
printf("%016"PRIx64"", x);
}
static void cnv_print(uint64_t x)
{
double f = x;
uint64_t y = f;
print_val(x);
printf(" -> ");
print_val(y);
printf("\n");
}
int main(void)
{
fesetround(FE_TONEAREST);
cnv_print(0x7fffffffffffffff);
fesetround(FE_DOWNWARD);
cnv_print(0x7fffffffffffffff);
fesetround(FE_UPWARD);
cnv_print(0x7fffffffffffffff);
fesetround(FE_TOWARDZERO);
cnv_print(0x7fffffffffffffff);
return 0;
}
More information about the Gcc-bugs
mailing list