[LLVMbugs] [Bug 3929] New: Rounding modes are ignored in gcc front end constant folding
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Thu Apr 2 19:04:06 PDT 2009
http://llvm.org/bugs/show_bug.cgi?id=3929
Summary: Rounding modes are ignored in gcc front end constant
folding
Product: new-bugs
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Keywords: miscompilation
Severity: normal
Priority: P2
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: llvm at nraynaud.com
CC: llvmbugs at cs.uiuc.edu
I toyed around with http://llvm.org/demo/index.cgi
and found that this code :
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>
#include <math.h>
int main(int argc, char **argv) {
#pragma STDC FENV_ACCESS ON
fesetround(FE_UPWARD);
double g = sin(0.9);
printf("%A\n", g);
fesetround(FE_DOWNWARD);
double h = sin(0.9);
printf("%A\n", h);
return 0;
}
produces the same bit patterns for g and h, which is obviously false
define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {
entry:
%0 = tail call i32 @fesetround(i32 2048) nounwind ; <i32>
[#uses=0]
%1 = tail call i32 (i8*, ...)* @printf(i8* noalias getelementptr ([4 x
i8]* @.str, i32 0, i32 0), double 0x3FE91103985DA841) nounwind ;
<i32> [#uses=0]
%2 = tail call i32 @fesetround(i32 1024) nounwind ; <i32>
[#uses=0]
%3 = tail call i32 (i8*, ...)* @printf(i8* noalias getelementptr ([4 x
i8]* @.str, i32 0, i32 0), double 0x3FE91103985DA841) nounwind ;
<i32> [#uses=0]
ret i32 0
}
here is the result on x86_32 :
nraynaud at macaron-2:~/Desktop/geek/fp$ gcc test2.c && ./a.out
0X1.91103985DA842P-1
0X1.91103985DA858P-1
This is a common IEEE 754 mistake.
Either, fesetround should be interpreted before folding the constant, or IEEE
754 shouldn't be folded in the presence of the pragma.
It should be noted that only the pragma allows for toying with rounding mode
(and flag bits), careless folding is free if the pragma is not there. So people
who don't care about ieee stuff get their usual speed, those that know ieee
stuff get what they bargained for, and speed is often the price to pay. Those
who try to play with rounding modes without setting the pragma spend hours
finding why it doesn't work reliably.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list