public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [alpha] Wrong code produced at -Os, -O2, and -O3
@ 2010-04-07 18:47 Matt Turner
  2010-04-08  9:06 ` Uros Bizjak
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Turner @ 2010-04-07 18:47 UTC (permalink / raw)
  To: gcc; +Cc: Uros Bizjak, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 1452 bytes --]

Hi Uros and Richard,
I was rewriting the Alpha sched_find_first_bit implementation for the
Linux Kernel, and in the process I think I've come across a gcc bug.

I rewrote the function using cmov instructions, and wrote a small
program to test its correctness and performance. I wrote the function
initially as an external .S file, and once I was reasonably sure it
was correct, converted it to C function with inline assembly.
Compiling both produce the exact same output, as shown.

<rewritten>:
        ldq     t0,0(a0)
        clr     t2
        ldq     t1,8(a0)
        cmoveq  t0,0x40,t2
        cmoveq  t0,t1,t0
        cttz    t0,t3
        addq    t3,t2,v0
        ret

In my test program, I found that when I executed the rewritten
implementation _before_ the reference implementation that it produced
bogus results. This only happens when using the C/inline asm function.
When compiled with the external .S file, the results are correct.

Attached is a tar.gz with my test code. Compile the test program with
`gcc -O -mcpu=... find.c rewritten.S test.c -o test` with optional
-D__REWRITTEN_INLINE and -D__REWRITTEN_FIRST. At -Os, -O2, or -O3 and
-D__REWRITTEN_INLINE and -D__REWRITTEN_FIRST the program will produce
incorrect results and assert(). At -O0 or -O1 or without one or both
of the -D flags, it will produce correct results. I've tested with
gcc-4.3.4 and gcc-4.4.2.

Thanks. Let me know what I can do to help further.

Matt Turner

[-- Attachment #2: sched_find_first_bit.tar.gz --]
[-- Type: application/x-gzip, Size: 1463 bytes --]

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

* Re: [alpha] Wrong code produced at -Os, -O2, and -O3
  2010-04-07 18:47 [alpha] Wrong code produced at -Os, -O2, and -O3 Matt Turner
@ 2010-04-08  9:06 ` Uros Bizjak
  2010-04-08 17:39   ` Matt Turner
  0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2010-04-08  9:06 UTC (permalink / raw)
  To: Matt Turner; +Cc: gcc, Richard Henderson

On Wed, Apr 7, 2010 at 8:38 PM, Matt Turner <mattst88@gmail.com> wrote:

> I was rewriting the Alpha sched_find_first_bit implementation for the
> Linux Kernel, and in the process I think I've come across a gcc bug.

[...]

> Thanks. Let me know what I can do to help further.

Please fill a Bugzilla bugreport with your problem. Otherwise, it will
be lost in the mailing lists.

Uros.

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

* Re: [alpha] Wrong code produced at -Os, -O2, and -O3
  2010-04-08  9:06 ` Uros Bizjak
@ 2010-04-08 17:39   ` Matt Turner
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Turner @ 2010-04-08 17:39 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc, Richard Henderson

On Thu, Apr 8, 2010 at 2:16 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Wed, Apr 7, 2010 at 8:38 PM, Matt Turner <mattst88@gmail.com> wrote:
>
>> I was rewriting the Alpha sched_find_first_bit implementation for the
>> Linux Kernel, and in the process I think I've come across a gcc bug.
>
> [...]
>
>> Thanks. Let me know what I can do to help further.
>
> Please fill a Bugzilla bugreport with your problem. Otherwise, it will
> be lost in the mailing lists.
>
> Uros.
>

Sure. Thanks for the email.

I've filed it in Bugzilla, with as small a test case as I can.

Thanks!
Matt

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

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

end of thread, other threads:[~2010-04-08 16:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-07 18:47 [alpha] Wrong code produced at -Os, -O2, and -O3 Matt Turner
2010-04-08  9:06 ` Uros Bizjak
2010-04-08 17:39   ` Matt Turner

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