public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: kevin diggs <diggskevin38@gmail.com>
To: Wander Lairson Costa <wander.lairson@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Program fails when optimizing for speed under gcc 4.6
Date: Tue, 20 Dec 2011 21:52:00 -0000	[thread overview]
Message-ID: <CAKTLLVRizwZi6QcrhU6_E0LKFg7jEFxb6Wuuitp=7M+-UkM-=g@mail.gmail.com> (raw)
In-Reply-To: <CAFsSK4Y9B4dYQ66AaTQcv3fh_kO4AmeFAYs6XXrVed+vvA-_xg@mail.gmail.com>

On Tue, Dec 20, 2011 at 2:13 PM, Wander Lairson Costa
<wander.lairson@gmail.com> wrote:
> Dear all,
>
> I have a home made alpha blend code that used to work until gcc 4.5
> but fails on gcc 4.6 (tested on gcc 4.6.1 [ubuntu] and gcc 4.6.2
> [archlinux]) when I optimize code for speed (-O1). If I optimize for
> size (-Os) it works fine. To make a long story short, the problem is
> that when optimizing for speed, gcc generates code that accesses local
> variables using the esp register, which cause troubles in some part of
> my code that is written in assembly:
>
>        __asm__ __volatile__ (
>            /* Initialize the counter and skip */
>            /* if the latter is equal to zero. */
>            "movl   %0,%%ecx\n\t"
>            "cmpl   $0,%%ecx\n\t"
>            "jz     not_blend\n\t"
>
>            /* Load the frame buffer pointers into the registers. */
>
>            "pushl      %%ebx\n\t"        <------ HERE IS THE ROOT OF
> THE PROBLEM
>            "movl       %1,%%edi\n\t"   <------ In this three lines
> gcc accesses %1, %2, and %3
>            "movl       %2,%%esi\n\t"   <------ variables using the esp register
>            "movl       %3,%%ebx\n\t"  <------
>
> The problem is that inside the assembly code, I do a "pushl %%ebx"
> instruction, which updates the esp register, and following it, I
> access local variables using the "%n" idiom, but gcc (when optimizing
> for speed) emits code that accesses the variables through esp
> register, which is no longer valid. When no optimization is applied or
> when optimizing for size, the local vars accesses are done through ebp
> register, and everything runs fine.
>
> Now I am in doubt if I am loosing some spec detail in IA32 that
> prohibit me from pushing things to the stack or if gcc is emitting
> some kind of invalid code. Any ideas?
>
> Thanks in advance.
>
> --
> Best Regards,
> Wander Lairson Costa

Hi,

Can you use 'O1 -fno-omit-frame-pointer'? Does O1 enable
omit-frame-pointer? You can also try -fverbose-asm to see the list of
-f options that are passed to cc1 (only useful in a -S compile). Maybe
you can look for the culprit that is haunting your code that way?

kevin

  reply	other threads:[~2011-12-20 21:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-20 20:16 Wander Lairson Costa
2011-12-20 21:52 ` kevin diggs [this message]
2011-12-20 22:41   ` Wander Lairson Costa
2011-12-21 23:24     ` Wander Lairson Costa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKTLLVRizwZi6QcrhU6_E0LKFg7jEFxb6Wuuitp=7M+-UkM-=g@mail.gmail.com' \
    --to=diggskevin38@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=wander.lairson@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).