From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30958 invoked by alias); 4 Jan 2008 17:49:03 -0000 Received: (qmail 30854 invoked by uid 48); 4 Jan 2008 17:48:20 -0000 Date: Fri, 04 Jan 2008 18:56:00 -0000 Subject: [Bug c/34678] New: Optimization generates incorrect code with -frounding-math option X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "merkert at comcast dot net" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-01/txt/msg00384.txt.bz2 The following function produces only a single division operation even when compiling with -frounding-math. I had read in a different PR (29186) that the pragma FENV_ACCESS is not supported, but that -frounding-math should produce the same effect (recognizing that the option is experimental as well). Here's the function: cat > div.c < void xdiv (double x, double y, double* lo, double* hi) { #pragma STDC FENV_ACCESS ON fesetround(FE_DOWNWARD); *lo = x/y; fesetround(FE_UPWARD); *hi = x/y; } EOF gcc -O -frounding-math div.c -S I get the following assembly-fragment on xdiv: .LFB2: movq %rbx, -24(%rsp) .LCFI0: movq %rbp, -16(%rsp) .LCFI1: movq %r12, -8(%rsp) .LCFI2: subq $56, %rsp .LCFI3: movsd %xmm0, 24(%rsp) movsd %xmm1, 16(%rsp) movq %rdi, %rbx movq %rsi, %r12 movl $1024, %edi call fesetround movsd 24(%rsp), %xmm0 divsd 16(%rsp), %xmm0 movsd %xmm0, 8(%rsp) movq 8(%rsp), %rbp movq %rbp, (%rbx) movl $2048, %edi call fesetround movq %rbp, (%r12) movq 32(%rsp), %rbx movq 40(%rsp), %rbp movq 48(%rsp), %r12 addq $56, %rsp ret .LFE2: Here's also a simple driver program: #include #include extern void xdiv(double x, double y, double* lo, double* hi); int main(int argc, char** argv) { double z1,z2; xdiv(1,10,&z1,&z2); printf(" rounding down 1/10 is %30.20g \n", z1); printf(" rounding up 1/10 is %30.20g \n", z2); assert(z1