This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/15422] New: fmod loop exposes non-efficient code generation in reg-stack.c
- From: "uros at kss-loka dot si" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 May 2004 15:08:07 -0000
- Subject: [Bug rtl-optimization/15422] New: fmod loop exposes non-efficient code generation in reg-stack.c
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
At the bottom of reg-stack.c file, there is a comment in convert_regs() function:
/* ??? Future: process inner loops first, and give them arbitrary
initial stacks which emit_swap_insn can modify. This ought to
prevent double fxch that often appears at the head of a loop. */
This anomaly is exposed with fmod() instruction with -O2 -ffast-math flags. This
testcase:
double test1d(double x, double y)
{
return fmod(x, y);
}
compiles to:
test1d:
fldl 4(%esp) <- parameter loads should be inverted in this case
fldl 12(%esp)
jmp .L2 <- jump
.p2align 4,,7
.L6:
fxch %st(1) <- double fxch
.L2:
fxch %st(1) <- double fxch
fprem
fnstsw %ax
sahf
jp .L6
fstp %st(1)
ret
Optimum code would be something like this:
test1d:
fldl 12(%esp)
fldl 4(%esp)
.p2align 4,,7
.L2:
fprem
fnstsw %ax
sahf
jp .L6
fstp %st(1)
ret
The problem can be seen in _.c.35.stack dump in the edge 1->1 in BB 1:
Basic block 0
Input stack: empty
insn 10 input stack: empty
insn 11 input stack: [ 8 ]
Expected live registers [ 8 9 ]
Output stack: [ 8 9 ]
Edge 0->1: new block; copying stack position
Basic block 1
Input stack: [ 8 9 ]
insn 13 input stack: [ 8 9 ]
Expected live registers [ 8 9 ]
Output stack: [ 9 8 ]
Edge 1->1: correcting stack to [ 8 9 ]
Edge 1->2: new block; pops needed
Basic block 2
Input stack: [ 8 ]
insn 17 input stack: [ 8 ]
insn 27 input stack: [ 8 ]
Expected live registers [ 8 ]
Output stack: [ 8 ]
Edge 2->-2: no changes needed
Edge 1->1 redirected to 3
--
Summary: fmod loop exposes non-efficient code generation in reg-
stack.c
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: uros at kss-loka dot si
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15422