Bug 20688 - [3.4 Regression] gcc miscompiles composition of sqrt() with inlined function
Summary: [3.4 Regression] gcc miscompiles composition of sqrt() with inlined function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 3.4.4
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-03-29 21:28 UTC by Christian Vogler
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Preprocessed test snippet for reproducing the bug (2.08 KB, application/x-gzip)
2005-03-29 21:29 UTC, Christian Vogler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Vogler 2005-03-29 21:28:58 UTC
GCC info: gcc -v

Reading specs from
/home/cvogler/addons/gcc-test/lib/gcc/x86_64-unknown-linux-gnu/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --prefix=/home/cvogler/addons/gcc-test
--disable-multilib
Thread model: posix
gcc version 3.4.3

The following test snippet shows a very reduced case of Cholesky factorization
code, which uses inline functions for array indexing. It is miscompiled with
these compiler flags on the x86_64 target:

gcc -Wall -O -finline-functions -o test test.c -lm

--- test.c ---
#include <math.h>

double getval()
{
  return -1.0;
}

int main(void)
{
  double y = sqrt(getval());
}
---

The result is in infinite loop, instead of the expected "nan." This generated
assembler snippet, in particular, looks incorrect:

---
.L3:
        sqrtsd  %xmm0, %xmm0
        ucomisd %xmm0, %xmm0
        jp      .L6
        je      .L4
.L6:
        movlpd  .LC3(%rip), %xmm0
        jmp     .L3
.L4:
        rep ; ret
---

In this snippet .L6 should contain a call to the sqrt function, but instead it
jumps back to .L3, causing an infinite loop. Suppressing inlining of functions
makes gcc generate correct code. Also, I could not reproduce the problem on a
32-bit x86 target.
Comment 1 Christian Vogler 2005-03-29 21:29:55 UTC
Created attachment 8491 [details]
Preprocessed test snippet for reproducing the bug
Comment 2 Andrew Pinski 2005-03-29 21:36:08 UTC
Fixed already in 3.4.4.
This might be a dup of another bug somewhere too.