From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10340 invoked by alias); 20 Dec 2011 20:14:31 -0000 Received: (qmail 10330 invoked by uid 22791); 20 Dec 2011 20:14:29 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM X-Spam-Check-By: sourceware.org Received: from mail-ee0-f47.google.com (HELO mail-ee0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Dec 2011 20:14:16 +0000 Received: by eeit10 with SMTP id t10so3175984eei.20 for ; Tue, 20 Dec 2011 12:14:15 -0800 (PST) Received: by 10.213.15.69 with SMTP id j5mr841721eba.128.1324412055289; Tue, 20 Dec 2011 12:14:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.213.110.197 with HTTP; Tue, 20 Dec 2011 12:13:34 -0800 (PST) From: Wander Lairson Costa Date: Tue, 20 Dec 2011 20:16:00 -0000 Message-ID: Subject: Program fails when optimizing for speed under gcc 4.6 To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-12/txt/msg00177.txt.bz2 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