public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el
@ 2015-09-27 21:49 aurelien at aurel32 dot net
  2015-09-27 23:26 ` [Bug target/67736] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: aurelien at aurel32 dot net @ 2015-09-27 21:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67736
           Summary: Wrong optimization with -fexpensive-optimizations on
                    mips64el
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aurelien at aurel32 dot net
  Target Milestone: ---
              Host: mips64el-unknown-linux-gnu
            Target: mips64el-unknown-linux-gnu
             Build: mips64el-unknown-linux-gnu

The following code is wrongly compiled on a mips64el target when using
-fexpensive-optimizations:

#include <inttypes.h>
#include <stdio.h>

int compare(uint64_t state, uint32_t *last, uint8_t buf)
{
    if (*last == ((state | buf) & 0xFFFFFFFF)) {
        printf("B %"PRIx64" %"PRIx32"\n", state, *last);
        return 0;
    }
    return 1;
}

It produces the following code:

00000000000009a0 <compare>:
 9a0:   30c200ff        andi    v0,a2,0xff
 9a4:   8ca60000        lw      a2,0(a1)
 9a8:   00441025        or      v0,v0,a0
 9ac:   10460004        beq     v0,a2,9c0 <compare+0x20>
 9b0:   24020001        li      v0,1
 9b4:   03e00008        jr      ra
 9b8:   00000000        nop
 9bc:   00000000        nop
...

Note how the comparison is done incorrectly, dropping the & 0xFFFFFFFF and
sign-extending the value when loading *last.

Using -fno-expensive-optimizations produces the following valid code:
00000000000009a0 <compare>:
 9a0:   30c200ff        andi    v0,a2,0xff
 9a4:   8ca60000        lw      a2,0(a1)
 9a8:   00441025        or      v0,v0,a0
 9ac:   7cc3f803        dext    v1,a2,0x0,0x20
 9b0:   7c42f803        dext    v0,v0,0x0,0x20
 9b4:   10620004        beq     v1,v0,9c8 <compare+0x28>
 9b8:   24020001        li      v0,1
 9bc:   03e00008        jr      ra
 9c0:   00000000        nop
 9c4:   00000000        nop
 9c8:   67bdfff0        daddiu  sp

Here both values are zero extended to 32-bit before the comparison.

Alternatively, when removing the line with the printf, GCC also produces
correct code, which is more optimized:

0000000000000960 <compare>:
 960:   30c600ff        andi    a2,a2,0xff
 964:   00c42025        or      a0,a2,a0
 968:   9ca20000        lwu     v0,0(a1)
 96c:   7c86f803        dext    a2,a0,0x0,0x20
 970:   00c21026        xor     v0,a2,v0
 974:   03e00008        jr      ra
 978:   0002102b        sltu    v0,zero,v0
 97c:   00000000        nop

Note that at least gcc 4.8.5, 4.9.3 and 5.2.1 are affected.


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

* [Bug target/67736] Wrong optimization with -fexpensive-optimizations on mips64el
  2015-09-27 21:49 [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el aurelien at aurel32 dot net
@ 2015-09-27 23:26 ` pinskia at gcc dot gnu.org
  2015-09-29 10:39 ` [Bug rtl-optimization/67736] " aurelien at aurel32 dot net
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-09-27 23:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you try the patch in
https://gcc.gnu.org/ml/gcc-patches/2012-05/msg00401.html ?

I never got around to updating it for the comments.


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

* [Bug rtl-optimization/67736] Wrong optimization with -fexpensive-optimizations on mips64el
  2015-09-27 21:49 [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el aurelien at aurel32 dot net
  2015-09-27 23:26 ` [Bug target/67736] " pinskia at gcc dot gnu.org
@ 2015-09-29 10:39 ` aurelien at aurel32 dot net
  2015-09-29 12:09 ` aurelien at aurel32 dot net
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: aurelien at aurel32 dot net @ 2015-09-29 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Aurelien Jarno <aurelien at aurel32 dot net> ---
Thanks for the patch. I have just tested it, and it indeed fixes the issue from
the testcase. I am currently trying to build ffmpeg, from which the testcase
has been extracted to see if all the issues are really fixed.


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

* [Bug rtl-optimization/67736] Wrong optimization with -fexpensive-optimizations on mips64el
  2015-09-27 21:49 [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el aurelien at aurel32 dot net
  2015-09-27 23:26 ` [Bug target/67736] " pinskia at gcc dot gnu.org
  2015-09-29 10:39 ` [Bug rtl-optimization/67736] " aurelien at aurel32 dot net
@ 2015-09-29 12:09 ` aurelien at aurel32 dot net
  2015-10-23 15:56 ` sje at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: aurelien at aurel32 dot net @ 2015-09-29 12:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Aurelien Jarno <aurelien at aurel32 dot net> ---
The ffmpeg testsuite is successful on mips64el-linux-gnu with this patch
applied.


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

* [Bug rtl-optimization/67736] Wrong optimization with -fexpensive-optimizations on mips64el
  2015-09-27 21:49 [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el aurelien at aurel32 dot net
                   ` (2 preceding siblings ...)
  2015-09-29 12:09 ` aurelien at aurel32 dot net
@ 2015-10-23 15:56 ` sje at gcc dot gnu.org
  2015-10-23 15:59 ` sje at gcc dot gnu.org
  2023-07-07  4:32 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: sje at gcc dot gnu.org @ 2015-10-23 15:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Steve Ellcey <sje at gcc dot gnu.org> ---
Author: sje
Date: Fri Oct 23 15:56:15 2015
New Revision: 229259

URL: https://gcc.gnu.org/viewcvs?rev=229259&root=gcc&view=rev
Log:
2015-10-23  Steve Ellcey  <sellcey@imgtec.com>
            Andrew Pinski  <apinski@cavium.com>

        PR rtl-optimization/67736
        * combine.c (simplify_comparison): Use gen_lowpart_or_truncate instead
        of gen_lowpart.

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


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

* [Bug rtl-optimization/67736] Wrong optimization with -fexpensive-optimizations on mips64el
  2015-09-27 21:49 [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el aurelien at aurel32 dot net
                   ` (3 preceding siblings ...)
  2015-10-23 15:56 ` sje at gcc dot gnu.org
@ 2015-10-23 15:59 ` sje at gcc dot gnu.org
  2023-07-07  4:32 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: sje at gcc dot gnu.org @ 2015-10-23 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Steve Ellcey <sje at gcc dot gnu.org> ---
Author: sje
Date: Fri Oct 23 15:58:33 2015
New Revision: 229260

URL: https://gcc.gnu.org/viewcvs?rev=229260&root=gcc&view=rev
Log:
2015-10-23  Steve Ellcey  <sellcey@imgtec.com>
            Andrew Pinski  <apinski@cavium.com>

        PR rtl-optimization/67736
        * gcc.dg/torture/pr67736.c: New test.
        * gcc.dg/combine-subregs.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/combine-subregs.c
    trunk/gcc/testsuite/gcc.dg/torture/pr67736.c
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug rtl-optimization/67736] Wrong optimization with -fexpensive-optimizations on mips64el
  2015-09-27 21:49 [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el aurelien at aurel32 dot net
                   ` (4 preceding siblings ...)
  2015-10-23 15:59 ` sje at gcc dot gnu.org
@ 2023-07-07  4:32 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-07  4:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |5.3

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

end of thread, other threads:[~2023-07-07  4:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-27 21:49 [Bug target/67736] New: Wrong optimization with -fexpensive-optimizations on mips64el aurelien at aurel32 dot net
2015-09-27 23:26 ` [Bug target/67736] " pinskia at gcc dot gnu.org
2015-09-29 10:39 ` [Bug rtl-optimization/67736] " aurelien at aurel32 dot net
2015-09-29 12:09 ` aurelien at aurel32 dot net
2015-10-23 15:56 ` sje at gcc dot gnu.org
2015-10-23 15:59 ` sje at gcc dot gnu.org
2023-07-07  4:32 ` 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).