public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands
@ 2010-10-25 10:13 siarhei.siamashka at gmail dot com
  2010-10-25 10:37 ` [Bug middle-end/46164] " siarhei.siamashka at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: siarhei.siamashka at gmail dot com @ 2010-10-25 10:13 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Local variables in specified registers don't work
                    correctly with inline asm operands
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: siarhei.siamashka@gmail.com


When testing with gcc 4.5.1

==== ARM ====

$ cat test.c

int f(int a)
{
  register int result asm("r0");
  asm (
    "add    r0, %[a], #123\n"
    : [result] "=&r" (result)
    : [a]      "r"   (a)
  );
  return result;
}

$ gcc -O2 -c test.c
$ objdump -d test.o

00000000 <f>:
   0:   e280007b        add     r0, r0, #123    ; 0x7b
   4:   e1a00003        mov     r0, r3
   8:   e12fff1e        bx      lr

Here the local variable 'result' gets assigned to register r3 instead of r0
causing all kind of problems.

==== x86-64 ====

$ cat test.c

int f(int a)
{
  register int result asm("edi");
  asm (
    "lea    0x7b(%[a]), %%edi\n"
    : [result] "=&r" (result)
    : [a]      "r"   (a)
  );
  return result;
}

$ gcc -O2 -c test.c
$ objdump -d test.o

0000000000000000 <f>:
   0:   67 8d 7f 7b             addr32 lea 0x7b(%edi),%edi
   4:   c3                      retq

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

And some final bits.

http://gcc.gnu.org/onlinedocs/gcc/Local-Reg-Vars.html#Local-Reg-Vars
http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

The documantation is a bit confusing, but it gives at least one example of
assigining variables to specified registers:

"Sometimes you need to make an asm operand be a specific register, but there's
no matching constraint letter for that register by itself. To force the operand
into that register, use a local variable for the operand and specify the
register in the variable declaration. See Explicit Reg Vars. Then for the asm
operand, use any register constraint letter that matches the register:

     register int *p1 asm ("r0") = ...;
     register int *p2 asm ("r1") = ...;
     register int *result asm ("r0");
     asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));"

Let's try to use something like that with x86-64:

/********************/
void abort();

int __attribute__((noinline)) f(int a)
{
  register int p1 asm ("edi");
  register int result asm ("edi");
  asm (
    "mov %2, %0\n"
    "add %2, %0\n"
    "add %2, %0\n"
    : "=r" (result) : "0"  (p1), "r" (a));
  return result;
}

int main()
{
    if (f(1) != 3)
        abort();
}

/********************/

This testcase fails.

So is it a bug in gcc? Or the documentation is wrong? Or I'm missing something?


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
@ 2010-10-25 10:37 ` siarhei.siamashka at gmail dot com
  2010-10-25 12:32 ` siarhei.siamashka at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: siarhei.siamashka at gmail dot com @ 2010-10-25 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Siarhei Siamashka <siarhei.siamashka at gmail dot com> 2010-10-25 10:37:13 UTC ---
Created attachment 22144
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22144
proposed testcase for x86_64


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
  2010-10-25 10:37 ` [Bug middle-end/46164] " siarhei.siamashka at gmail dot com
@ 2010-10-25 12:32 ` siarhei.siamashka at gmail dot com
  2010-10-27 21:13 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: siarhei.siamashka at gmail dot com @ 2010-10-25 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

Siarhei Siamashka <siarhei.siamashka at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #22144|0                           |1
        is obsolete|                            |

--- Comment #2 from Siarhei Siamashka <siarhei.siamashka at gmail dot com> 2010-10-25 12:32:01 UTC ---
Created attachment 22145
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22145
updated testcase (x86_64)

Actually the previous testcase was not very good. It tried to simulate
earlyclobber operand by specifying it both as input and output, but because
"p1" was actually not initialized, gcc may be allowed to optimize it and screw
up everything (without any kind of warnings, but that's another story).

So the problem is actually related to using specified registers for
earlyclobber output operands in such a way that they try to use the same
registers as function arguments.


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
  2010-10-25 10:37 ` [Bug middle-end/46164] " siarhei.siamashka at gmail dot com
  2010-10-25 12:32 ` siarhei.siamashka at gmail dot com
@ 2010-10-27 21:13 ` pinskia at gcc dot gnu.org
  2014-08-13  7:47 ` tp+gcc at pambor dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-10-27 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ra, wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.10.27 21:13:00
     Ever Confirmed|0                           |1
      Known to fail|                            |4.1.2, 4.3.2, 4.6.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-10-27 21:13:00 UTC ---
Confirmed, The register allocator is causing it.  I think it does not take into
account the "&" so reload will correct it.  (this was true at least in the old
RA in 4.3 and before).


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
                   ` (2 preceding siblings ...)
  2010-10-27 21:13 ` pinskia at gcc dot gnu.org
@ 2014-08-13  7:47 ` tp+gcc at pambor dot com
  2014-08-13  7:51 ` tp+gcc at pambor dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tp+gcc at pambor dot com @ 2014-08-13  7:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46164

--- Comment #4 from Tim Pambor <tp+gcc at pambor dot com> ---
Created attachment 33307
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33307&action=edit
testcase for gcc 4.9.1

I think this bug is still present in gcc 4.9.1 and 4.8.4.

I could reproduce the problem with the attached testcase using gcc 4.8.4 with
-O1 and -Og and 4.9.1 with -O1. -O0, -O2, -O3, -Os generated correct code. It
generated the following assembler code:

...
  mov r0, r0    @ r0
  mov r4, r4    @ r1
  mov r2, r2    @ r2
...

Expected would have been:

...
  mov r0, r0    @ r0
  mov r1, r1    @ r1
  mov r2, r2    @ r2
...


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
                   ` (3 preceding siblings ...)
  2014-08-13  7:47 ` tp+gcc at pambor dot com
@ 2014-08-13  7:51 ` tp+gcc at pambor dot com
  2014-08-13  7:55 ` tp+gcc at pambor dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tp+gcc at pambor dot com @ 2014-08-13  7:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46164

Tim Pambor <tp+gcc at pambor dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #33307|0                           |1
        is obsolete|                            |

--- Comment #5 from Tim Pambor <tp+gcc at pambor dot com> ---
Created attachment 33308
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33308&action=edit
updated testcase for gcc 4.9.1


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
                   ` (4 preceding siblings ...)
  2014-08-13  7:51 ` tp+gcc at pambor dot com
@ 2014-08-13  7:55 ` tp+gcc at pambor dot com
  2015-01-22 11:02 ` Hale.Wang at arm dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tp+gcc at pambor dot com @ 2014-08-13  7:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46164

--- Comment #6 from Tim Pambor <tp+gcc at pambor dot com> ---
Created attachment 33309
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33309&action=edit
"-da" rtl files for testcase


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
                   ` (5 preceding siblings ...)
  2014-08-13  7:55 ` tp+gcc at pambor dot com
@ 2015-01-22 11:02 ` Hale.Wang at arm dot com
  2015-01-26 10:00 ` Hale.Wang at arm dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Hale.Wang at arm dot com @ 2015-01-22 11:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46164

Hale Wang <Hale.Wang at arm dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Hale.Wang at arm dot com

--- Comment #7 from Hale Wang <Hale.Wang at arm dot com> ---
(In reply to Tim Pambor from comment #4)
> Created attachment 33307 [details]
> testcase for gcc 4.9.1
> 
> I think this bug is still present in gcc 4.9.1 and 4.8.4.
> 
> I could reproduce the problem with the attached testcase using gcc 4.8.4
> with -O1 and -Og and 4.9.1 with -O1. -O0, -O2, -O3, -Os generated correct
> code. It generated the following assembler code:
> 
> ...
>   mov r0, r0	@ r0
>   mov r4, r4	@ r1
>   mov r2, r2	@ r2
> ...
> 
> Expected would have been:
> 
> ...
>   mov r0, r0	@ r0
>   mov r1, r1	@ r1
>   mov r2, r2	@ r2
> ...

The combine pass combined the volatile register which caused this bug.

The expected assembler code should be:

  mov r4, .L_temp
  mov r1, r4
  ...
  mov r0, r0    @ r0
  mov r1, r1    @ r1
  mov r2, r2    @ r2

But GCC combined the insns, and the code is generated as:

  mov r4, .L_temp
  ...
  mov r0, r0    @ r0
  mov r4, r4    @ r1
  mov r2, r2    @ r2

The register 'r1' is defined as volatile in this case. It should not be
combined.
>From gcc-bugs-return-474357-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jan 22 11:08:28 2015
Return-Path: <gcc-bugs-return-474357-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 17031 invoked by alias); 22 Jan 2015 11:08:26 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 16938 invoked by uid 48); 22 Jan 2015 11:08:18 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/63307] [4.9 Regression] Cilk+ breaks -fcompare-debug bootstrap
Date: Thu, 22 Jan 2015 11:08:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.9.1
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P1
X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.9.3
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on assigned_to short_desc everconfirmed
Message-ID: <bug-63307-4-24Lezv9htK@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63307-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63307-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-01/txt/msg02351.txt.bz2
Content-length: 783

https://gcc.gnu.org/bugzilla/show_bug.cgi?idc307

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2015-01-22
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
            Summary|[4.9/5 Regression] Cilk+    |[4.9 Regression] Cilk+
                   |breaks -fcompare-debug      |breaks -fcompare-debug
                   |bootstrap                   |bootstrap
     Ever confirmed|0                           |1

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
                   ` (6 preceding siblings ...)
  2015-01-22 11:02 ` Hale.Wang at arm dot com
@ 2015-01-26 10:00 ` Hale.Wang at arm dot com
  2015-01-27  8:03 ` Hale.Wang at arm dot com
  2024-03-26 22:21 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: Hale.Wang at arm dot com @ 2015-01-26 10:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46164

--- Comment #8 from Hale Wang <Hale.Wang at arm dot com> ---
I have submitted a patch to community for further discussion. Refer to:
https://gcc.gnu.org/ml/gcc-patches/2015-01/msg02238.html.


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
                   ` (7 preceding siblings ...)
  2015-01-26 10:00 ` Hale.Wang at arm dot com
@ 2015-01-27  8:03 ` Hale.Wang at arm dot com
  2024-03-26 22:21 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: Hale.Wang at arm dot com @ 2015-01-27  8:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46164

--- Comment #9 from Hale Wang <Hale.Wang at arm dot com> ---
Hi Tim,

Your testcase is caused by the combine. It's not the same with Siarhei's test
case. So I think we should divide your test case to another bug.

And my patch is only used to fix the bug with your test case. So I will submit
a new bug to record your comments.

Thanks,
Hale


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

* [Bug middle-end/46164] Local variables in specified registers don't work correctly with inline asm operands
  2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
                   ` (8 preceding siblings ...)
  2015-01-27  8:03 ` Hale.Wang at arm dot com
@ 2024-03-26 22:21 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-26 22:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46164

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Turns out this is a dup of bug 87600. See bug 87600 comment #3 which is exactly
the same testcase as in comment #0 here (except for aarch64).

*** This bug has been marked as a duplicate of bug 87600 ***

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

end of thread, other threads:[~2024-03-26 22:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-25 10:13 [Bug middle-end/46164] New: Local variables in specified registers don't work correctly with inline asm operands siarhei.siamashka at gmail dot com
2010-10-25 10:37 ` [Bug middle-end/46164] " siarhei.siamashka at gmail dot com
2010-10-25 12:32 ` siarhei.siamashka at gmail dot com
2010-10-27 21:13 ` pinskia at gcc dot gnu.org
2014-08-13  7:47 ` tp+gcc at pambor dot com
2014-08-13  7:51 ` tp+gcc at pambor dot com
2014-08-13  7:55 ` tp+gcc at pambor dot com
2015-01-22 11:02 ` Hale.Wang at arm dot com
2015-01-26 10:00 ` Hale.Wang at arm dot com
2015-01-27  8:03 ` Hale.Wang at arm dot com
2024-03-26 22:21 ` pinskia at gcc dot gnu.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).