This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/42590] New: unnecessary stack frame set up
- From: "andi-gcc at firstfloor dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Jan 2010 06:58:50 -0000
- Subject: [Bug middle-end/42590] New: unnecessary stack frame set up
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Continuation from 42586 and 42585 who handle other missed optimizations
for this test case.
>From one of the examples of
http://embed.cs.utah.edu/embarrassing/dec_09/harvest/gcc-head_llvm-gcc-head/
struct _fat_ptr
{
unsigned char *curr;
unsigned char *base;
unsigned char *last_plus_one;
};
int Cyc_string_ungetc (int ignore, struct _fat_ptr *sptr);
int
Cyc_string_ungetc (int ignore, struct _fat_ptr *sptr)
{
struct _fat_ptr *_T0;
struct _fat_ptr *_T1;
struct _fat_ptr _T2;
int _T3;
struct _fat_ptr _ans;
int _change;
{
_T0 = sptr;
_T1 = sptr;
_T2 = *sptr;
_T3 = -1;
_ans = _T2;
_change = -1;
_ans.curr += 4294967295U;
*sptr = _ans;
return (0);
}
}
generates
hen compiled with -O2 -m32 on 4.5.0 20091219 generates
Cyc_string_ungetc:
subl $32, %esp
movl 40(%esp), %eax
movl (%eax), %edx
subl $1, %edx
movl %edx, (%eax)
xorl %eax, %eax
addl $32, %esp
ret
The stack frame manipulation is completely unnecessary.
A.Pinski commented on the other bug on this:
ell one thing is SRA does not do its job which is why there is useless stack
frame changes.
------- Comment #2 From Andrew Pinski 2010-01-03 06:27 [reply] -------
Oh and -Os is very bad looking :).
------- Comment #3 From Andrew Pinski 2010-01-03 06:30 [reply] -------
Oh in fact I think the reason is the SRA issue. In that:
int
Cyc_string_ungetc (int ignore, struct _fat_ptr *sptr)
{
sptr->curr += 4294967295U;
}
Works.
------- Comment #4 From Andrew Pinski 2010-01-03 06:33 [reply] -------
Hmm, 4.5 is worse off than 4.4 with respect of the stack space usage.
------- Comment #5 From Andrew Pinski 2010-01-03 06:35 [reply] -------
4.5 has:
_T2 = *sptr_1(D);
_T2$curr_14 = sptr_1(D)->curr;
_ans = _T2;
D.2697_7 = _T2$curr_14 + -1;
*sptr_1(D) = _ans;
sptr_1(D)->curr = D.2697_7;
While 4.4 does:
_T2$base = sptr->base;
D.1587 = sptr->curr + -1;
sptr->last_plus_one = sptr->last_plus_one;
sptr->base = _T2$base;
sptr->curr = D.1587;
------- Comment #6 From Andrew Pinski 2010-01-03 06:38 [reply] -------
I think if we get the old SRA behavior back for this code, we will get this
optimization in 4.5 since we remove the sptr->base and the other unnecessary
store during PRE.
--
Summary: unnecessary stack frame set up
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andi-gcc at firstfloor dot org
GCC host triplet: x86_64-linux
GCC target triplet: x86_64-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42590