public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/28686]  New: ebp from clobber list used as operand
@ 2006-08-10 19:45 Martin dot vGagern at gmx dot net
  2006-08-10 19:49 ` [Bug inline-asm/28686] " Martin dot vGagern at gmx dot net
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Martin dot vGagern at gmx dot net @ 2006-08-10 19:45 UTC (permalink / raw)
  To: gcc-bugs

#ifndef __PIC__
# define REG "ebx"
#else
# define REG "ebp"
#endif

#ifndef NBEFORE
void some_function_before(){
}
#endif

void test_function (){
    long var = 42;
    asm volatile(
             "inc %0\n#DEBUG %%0=%0, clobber: %%"REG", ..."
             :"+rm"(var)
             :
             :"%"REG"","%ecx","%esi","%edi","%edx","%eax");
}

========================

This little piece of code did several strange things for different flags:

1. #DEBUG %0=%ebp, clobber: %ebp, ...
   e.g. -fPIC -fomit-frame-pointer -O2, not -DNBEFORE

   This is the core of my bug report. The compiler should never ever use a
   register from the clobber list to store an operand. It doesn't do this
   for ebx, and it doen't do this if there function containing the asm is
   the first in the translation unit.
   But for ebp and with another function before, this strange bug occurs.
   Another function making a difference looks a bit like bug 28635

2. can't find a register in class 'GENERAL_REGS' while reloading 'asm'
   e.g. -O1, not -fomit-frame-pointer

   This seems to be a problem of -O1. Probably the compiler decides to use
   the r alternative and has problems falling back to m when this does not
   work.
   Perhaps the rationale is that gcc only looks at how to get the variables
   into the asm code with the least number of operations, and it's the
   programmer's task to make sure all mentioned operand constraints are
   possible on the target architecture. But this would be strange.
   If it were -O0 instead of -O1 I'd say it's bug 11203

3. #DEBUG %0=-12(%ebp), clobber: %ebp, ...
   e.g. -fPIC -O0, not -fomit-frame-pointer

   Seems like clobber lists get completely ignored for -O0. Perhaps this
   makes sense, as the compiler doen't have to care about registers being
   clobbered if all variables are stored in memory.
   Still this is strange behaviour.
   This is bug 11807


-- 
           Summary: ebp from clobber list used as operand
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Martin dot vGagern at gmx dot net
 GCC build triplet: i686-pc-linux-gnu-gcc
  GCC host triplet: i686-pc-linux-gnu-gcc
GCC target triplet: i686-pc-linux-gnu-gcc


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
@ 2006-08-10 19:49 ` Martin dot vGagern at gmx dot net
  2007-01-25 11:06 ` Martin dot vGagern at gmx dot net
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Martin dot vGagern at gmx dot net @ 2006-08-10 19:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from Martin dot vGagern at gmx dot net  2006-08-10 19:49 -------
Created an attachment (id=12058)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12058&action=view)
Test case including compilation result table

This is the above test case, and appended is a table matching compiler flags to
error messages or register allocation information.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
  2006-08-10 19:49 ` [Bug inline-asm/28686] " Martin dot vGagern at gmx dot net
@ 2007-01-25 11:06 ` Martin dot vGagern at gmx dot net
  2007-01-30 19:09 ` ian at airs dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Martin dot vGagern at gmx dot net @ 2007-01-25 11:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from Martin dot vGagern at gmx dot net  2007-01-25 11:06 -------
As this has been unconfirmed for so long and should be relatively easy to
confirm, here are the commands to reproduce the problems above:

gcc -fPIC -fomit-frame-pointer -O2 -S ebp.c && grep DEBUG ebp.s
gcc                            -O1 -S ebp.c && grep DEBUG ebp.s
gcc -fPIC                      -O0 -S ebp.c && grep DEBUG ebp.s

In case you want to reproduce all the combinations given in the table at the
end of my source file, you can use this bash loop:

for ((i=0; i < 32; ++i)); do
  ARGS="-O$((i%4))"; 
  ARGS="$( [[ $((i&4)) -eq 0 ]] || echo "-fomit-frame-pointer ")$ARGS";
  ARGS="$( [[ $((i&8)) -eq 0 ]] || echo "-fPIC ")$ARGS";
  ARGS="$( [[ $((i&16)) -eq 0 ]] || echo "-DNBEFORE ")$ARGS";
  echo "-- $ARGS --";
  gcc $ARGS -S ebp.c && grep DEBUG ebp.s
done

It might be you can reproduce this behaviour, but are not certain it is a bug.
I can understand you might doubt a single of my three mentioned problems, but
do you really believe they are all three as things should be? If in doubt,
perhaps best concentrate on problem 1, ebp being clobbered and still used.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
  2006-08-10 19:49 ` [Bug inline-asm/28686] " Martin dot vGagern at gmx dot net
  2007-01-25 11:06 ` Martin dot vGagern at gmx dot net
@ 2007-01-30 19:09 ` ian at airs dot com
  2007-01-30 20:17 ` michael dot meissner at amd dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ian at airs dot com @ 2007-01-30 19:09 UTC (permalink / raw)
  To: gcc-bugs



-- 

ian at airs dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-01-30 19:09:28
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
                   ` (2 preceding siblings ...)
  2007-01-30 19:09 ` ian at airs dot com
@ 2007-01-30 20:17 ` michael dot meissner at amd dot com
  2007-01-30 21:43 ` spark at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: michael dot meissner at amd dot com @ 2007-01-30 20:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from michael dot meissner at amd dot com  2007-01-30 20:17 -------
Created an attachment (id=12982)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12982&action=view)
Secondary error

Note, this is 32-bit only.  If you compile epb2.c with -fpic -m32 and no
optimization, it generates incorrect code, in that at -O0 it does not omit the
frame pointer, but the asm is claimed to clobber %ebp, and subsequent local
variables will use %ebp.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
                   ` (3 preceding siblings ...)
  2007-01-30 20:17 ` michael dot meissner at amd dot com
@ 2007-01-30 21:43 ` spark at gcc dot gnu dot org
  2007-01-31  0:28 ` spark at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: spark at gcc dot gnu dot org @ 2007-01-30 21:43 UTC (permalink / raw)
  To: gcc-bugs



-- 

spark at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|seongbae dot park at gmail  |
                   |dot com                     |
         AssignedTo|unassigned at gcc dot gnu   |spark at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-01-30 19:09:28         |2007-01-30 21:43:48
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
                   ` (4 preceding siblings ...)
  2007-01-30 21:43 ` spark at gcc dot gnu dot org
@ 2007-01-31  0:28 ` spark at gcc dot gnu dot org
  2007-02-01 17:47 ` spark at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: spark at gcc dot gnu dot org @ 2007-01-31  0:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from spark at gcc dot gnu dot org  2007-01-31 00:28 -------
Looks like eliminable_regset is not cleared per every invocation of
global_alloc, making stale bits from the compilation of previous function hang
around - hence a presence of a previous function makes difference. 
Following patch seems to fix -O2 problem.
I'm now on to -O1 and -O0 issues.

Index: global.c
===================================================================
--- global.c    (revision 121353)
+++ global.c    (working copy)
@@ -354,6 +354,7 @@ global_alloc (void)
      are safe to use only within a basic block.  */

   CLEAR_HARD_REG_SET (no_global_alloc_regs);
+  CLEAR_HARD_REG_SET (eliminable_regset);

   /* Build the regset of all eliminable registers and show we can't use those
      that we already know won't be eliminated.  */
@@ -2548,4 +2549,3 @@ struct tree_opt_pass pass_global_alloc =
   TODO_ggc_collect,                     /* todo_flags_finish */
   'g'                                   /* letter */
 };
-


-- 

spark at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |spark at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
                   ` (5 preceding siblings ...)
  2007-01-31  0:28 ` spark at gcc dot gnu dot org
@ 2007-02-01 17:47 ` spark at gcc dot gnu dot org
  2007-02-01 23:15 ` spark at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: spark at gcc dot gnu dot org @ 2007-02-01 17:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from spark at gcc dot gnu dot org  2007-02-01 17:47 -------
-O1 error problem is due to constant assignment of var.
If you replace:
  long var = 42; 
with something like:
  long var = func();

It compiles without an error (though it still has the #3 problem
of using %ebp even though it's marked clobbered).

This is a corner case for reload, because it knows the register contains a
constant, and thinks there will be at least some scratch register to load it
to. Unfortunately, due to the problematic asm statement having clobbers for all
registers (except %ebp, but %ebp is not available for general allocation
without -fomit-frame-pointer) there's no register available to load the
constant to.

So, the workaround for this problem is to have a local variable that's not
initialized from a constant.

So I'm deferring this #2 problem, and will take a look at #3 now.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
                   ` (6 preceding siblings ...)
  2007-02-01 17:47 ` spark at gcc dot gnu dot org
@ 2007-02-01 23:15 ` spark at gcc dot gnu dot org
  2007-02-06 19:44 ` spark at gcc dot gnu dot org
  2007-03-13 23:43 ` spark at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: spark at gcc dot gnu dot org @ 2007-02-01 23:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from spark at gcc dot gnu dot org  2007-02-01 23:15 -------
Subject: Bug 28686

Author: spark
Date: Thu Feb  1 23:15:13 2007
New Revision: 121477

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121477
Log:
2007-2-01   Seongbae Park <seongbae.park@gmail.com>

        PR inline-asm/28686
        * global.c (global_alloc): Add mising initialization of
        ELIMINABLE_REGSET.

2007-02-01  Roger Sayle  <roger@eyesopen.com>



Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/global.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
                   ` (7 preceding siblings ...)
  2007-02-01 23:15 ` spark at gcc dot gnu dot org
@ 2007-02-06 19:44 ` spark at gcc dot gnu dot org
  2007-03-13 23:43 ` spark at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: spark at gcc dot gnu dot org @ 2007-02-06 19:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from spark at gcc dot gnu dot org  2007-02-06 19:43 -------
Subject: Bug 28686

Author: spark
Date: Tue Feb  6 19:43:41 2007
New Revision: 121663

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121663
Log:
2007-02-06  Seongbae Park <seongbae.park@gmail.com>

        PR inline-asm/28686
        * global.c (compute_regsets): New function.
        (global_alloc): Refactored ELIMINABLE_REGSET
        and NO_GLOBAL_ALLOC_REGS computation out.
        (rest_of_handle_global_alloc): Call compute_regsets()
        for non-optimizing case.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/global.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug inline-asm/28686] ebp from clobber list used as operand
  2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
                   ` (8 preceding siblings ...)
  2007-02-06 19:44 ` spark at gcc dot gnu dot org
@ 2007-03-13 23:43 ` spark at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: spark at gcc dot gnu dot org @ 2007-03-13 23:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from spark at gcc dot gnu dot org  2007-03-13 23:43 -------
I believe all issues are fixed at this point,
except for the extra error message of "can't find a register".
But since it's accompanied with a proper error message,
I don't think this is a problem anymore.

$gcc -fPIC -fomit-frame-pointer -O2 -S t.c && grep DEBUG t.s
#DEBUG %0=(%esp), clobber: %ebp, ...
$gcc -DNBEFORE=1 -fPIC -fomit-frame-pointer -O2 -S t.c && grep DEBUG t.s
#DEBUG %0=(%esp), clobber: %ebp, ...
$gcc                            -O1 -S t.c $@ && grep DEBUG t.s
t.c: In function 'test_function':
t.c:15: error: can't find a register in class 'GENERAL_REGS' while reloading
'asm'
t.c:15: error: 'asm' operand has impossible constraints
$gcc                           -O1 -fPIC -S t.c $@ && grep DEBUG t.s
t.c: In function 'test_function':
t.c:20: error: bp cannot be used in asm here
t.c:15: error: can't find a register in class 'GENERAL_REGS' while reloading
'asm'
t.c:15: error: 'asm' operand has impossible constraints
$gcc -fPIC                      -O0 -S t.c && grep DEBUG t.s
t.c: In function 'test_function':
t.c:20: error: bp cannot be used in asm here
$gcc -fPIC                      -O0 -S t.c -fomit-frame-pointer && grep DEBUG
t.s
#DEBUG %0=12(%esp), clobber: %ebp, ...


-- 

spark at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28686


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-03-13 23:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-10 19:45 [Bug inline-asm/28686] New: ebp from clobber list used as operand Martin dot vGagern at gmx dot net
2006-08-10 19:49 ` [Bug inline-asm/28686] " Martin dot vGagern at gmx dot net
2007-01-25 11:06 ` Martin dot vGagern at gmx dot net
2007-01-30 19:09 ` ian at airs dot com
2007-01-30 20:17 ` michael dot meissner at amd dot com
2007-01-30 21:43 ` spark at gcc dot gnu dot org
2007-01-31  0:28 ` spark at gcc dot gnu dot org
2007-02-01 17:47 ` spark at gcc dot gnu dot org
2007-02-01 23:15 ` spark at gcc dot gnu dot org
2007-02-06 19:44 ` spark at gcc dot gnu dot org
2007-03-13 23:43 ` spark at gcc dot gnu dot org

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).