public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/42587] bswap not recognized for memory
       [not found] <bug-42587-4@http.gcc.gnu.org/bugzilla/>
@ 2012-02-22 13:51 ` xiaoyuanbo at yeah dot net
  2021-05-08 13:17 ` peter at cordes dot ca
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: xiaoyuanbo at yeah dot net @ 2012-02-22 13:51 UTC (permalink / raw)
  To: gcc-bugs

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

xiaoyuanbo <xiaoyuanbo at yeah dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xiaoyuanbo at yeah dot net

--- Comment #6 from xiaoyuanbo <xiaoyuanbo at yeah dot net> 2012-02-22 12:59:44 UTC ---
i know


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

* [Bug tree-optimization/42587] bswap not recognized for memory
       [not found] <bug-42587-4@http.gcc.gnu.org/bugzilla/>
  2012-02-22 13:51 ` [Bug tree-optimization/42587] bswap not recognized for memory xiaoyuanbo at yeah dot net
@ 2021-05-08 13:17 ` peter at cordes dot ca
  2021-05-09 21:02 ` andi at firstfloor dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: peter at cordes dot ca @ 2021-05-08 13:17 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Cordes <peter at cordes dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter at cordes dot ca

--- Comment #12 from Peter Cordes <peter at cordes dot ca> ---
(In reply to Andi Kleen from comment #11)
> Only when the first test case is fixed too

https://godbolt.org/z/7M8cx3vT1  GCC8.1 -O3 for x86-64

        push    rbx
        mov     ebx, edi
        call    acpi_ut_track_stack_ptr
        mov     eax, ebx
        pop     rbx
        bswap   eax
        ret


The code in the initial report optimizes to bswap with GCC8.1 and later.
Is that the test case you meant?  GCC8.1 was released on May 2, 2018, well
before your Nov comment, so maybe you meant something else.

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

* [Bug tree-optimization/42587] bswap not recognized for memory
       [not found] <bug-42587-4@http.gcc.gnu.org/bugzilla/>
  2012-02-22 13:51 ` [Bug tree-optimization/42587] bswap not recognized for memory xiaoyuanbo at yeah dot net
  2021-05-08 13:17 ` peter at cordes dot ca
@ 2021-05-09 21:02 ` andi at firstfloor dot org
  2021-05-10 12:21 ` cvs-commit at gcc dot gnu.org
  2021-05-10 12:22 ` hjl.tools at gmail dot com
  4 siblings, 0 replies; 10+ messages in thread
From: andi at firstfloor dot org @ 2021-05-09 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from andi at firstfloor dot org ---
> The code in the initial report optimizes to bswap with GCC8.1 and later.
> Is that the test case you meant?  GCC8.1 was released on May 2, 2018, well
> before your Nov comment, so maybe you meant something else.

Should be ok to close then. Thanks

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

* [Bug tree-optimization/42587] bswap not recognized for memory
       [not found] <bug-42587-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-05-09 21:02 ` andi at firstfloor dot org
@ 2021-05-10 12:21 ` cvs-commit at gcc dot gnu.org
  2021-05-10 12:22 ` hjl.tools at gmail dot com
  4 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-10 12:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:

https://gcc.gnu.org/g:1f94ed3b4c308c9da7baf59ecbc0f953e994f9c4

commit r12-664-g1f94ed3b4c308c9da7baf59ecbc0f953e994f9c4
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat May 8 07:23:25 2021 -0700

    Add a test for PR tree-optimization/42587

            PR tree-optimization/42587
            * gcc.dg/optimize-bswapsi-6.c: New test.

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

* [Bug tree-optimization/42587] bswap not recognized for memory
       [not found] <bug-42587-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2021-05-10 12:21 ` cvs-commit at gcc dot gnu.org
@ 2021-05-10 12:22 ` hjl.tools at gmail dot com
  4 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2021-05-10 12:22 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |8.2

--- Comment #15 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed as of GCC 8.2

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

* [Bug tree-optimization/42587] bswap not recognized for memory
  2010-01-03  6:15 [Bug tree-optimization/42587] New: bswap not recognized for union andi-gcc at firstfloor dot org
                   ` (3 preceding siblings ...)
  2010-01-06 14:07 ` jamborm at gcc dot gnu dot org
@ 2010-02-27 20:04 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-02-27 20:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2010-02-27 20:04 -------
*** Bug 43197 has been marked as a duplicate of this bug. ***


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kai dot extern at googlemail
                   |                            |dot com


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


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

* [Bug tree-optimization/42587] bswap not recognized for memory
  2010-01-03  6:15 [Bug tree-optimization/42587] New: bswap not recognized for union andi-gcc at firstfloor dot org
                   ` (2 preceding siblings ...)
  2010-01-03 16:26 ` rguenth at gcc dot gnu dot org
@ 2010-01-06 14:07 ` jamborm at gcc dot gnu dot org
  2010-02-27 20:04 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 10+ messages in thread
From: jamborm at gcc dot gnu dot org @ 2010-01-06 14:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jamborm at gcc dot gnu dot org  2010-01-06 14:07 -------
(In reply to comment #2)
> SRA here again does somthing stupid:
> 

As I have already told richi on IRC, if "in.value = value_1(D)" was an
assignment of two unions, it would have loaded the chars from the rhs
and thus make the union unnecessary.  But it cannot get the chars from
the RHS as it is now and so uses the union to do the type conversion.

I see no way to avoid this other than a third SRA scan of the entire
function to catch cases like this and not pessimize other situations.
I have put this to the bottom of my TODO list nevertheless, just in
case, but will remove myself from the CC list as the main bug is
something entirely different.  Feel free to add me if there is
anything else I should be aware of.  Thanks.


-- 

jamborm at gcc dot gnu dot org changed:

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


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


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

* [Bug tree-optimization/42587] bswap not recognized for memory
  2010-01-03  6:15 [Bug tree-optimization/42587] New: bswap not recognized for union andi-gcc at firstfloor dot org
  2010-01-03 10:58 ` [Bug tree-optimization/42587] bswap not recognized for memory rguenth at gcc dot gnu dot org
  2010-01-03 16:01 ` rguenth at gcc dot gnu dot org
@ 2010-01-03 16:26 ` rguenth at gcc dot gnu dot org
  2010-01-06 14:07 ` jamborm at gcc dot gnu dot org
  2010-02-27 20:04 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-03 16:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2010-01-03 16:26 -------
Similar example not handled by bswap recognition:

typedef unsigned char u8;
typedef unsigned int u32;
union __anonunion
{
  u32 value;
  u8 bytes[4];
};
u32
acpi_ut_dword_byte_swap (u32 value)
{
  union __anonunion in;
  in.value = value;
  return (((((in.bytes[0] << 8) | in.bytes[1]) << 8) | in.bytes[2]) << 8) |
in.bytes[3];
}

here we also hit the recursion depth of the bswap recognition.  Not so with

typedef unsigned char u8;
typedef unsigned int u32;
union __anonunion
{
  u32 value;
  u8 bytes[4];
};
u32
acpi_ut_dword_byte_swap (u32 value)
{
  union __anonunion in;
  in.value = value;
  return (((in.bytes[0] << 8) | in.bytes[1]) << 16) | ((in.bytes[2] << 8) |
in.bytes[3]);
}

but we do not handle

# VUSE <.MEM_18>
in$bytes$2_25 = in.bytes[2];

as bases (we probably could and it woudldn't be too hard - harder for
the case with pointer arithmetic though).  We end up trying with
in$bytes$2_25 as base.  Here:

        case BIT_IOR_EXPR:
          source_expr1 = find_bswap_1 (rhs1_stmt, &n1, limit - 1);
          if (!source_expr1)
            return NULL_TREE;

          source_expr2 = find_bswap_1 (rhs2_stmt, &n2, limit - 1);
          if (source_expr1 != source_expr2
              || n1.size != n2.size)
            return NULL_TREE;

we'd have to detect the source exprs common memory and adjust the
piecewise symbolic numbers and create a common source expr.  The
idea would be to combine in.bytes[2] and in.bytes[3] to
V_C_E <int> (in.bytes).  As said it's going to me more complicated
for accesses via pointers, *p, *(p+1), ...

Note that once we extend this for memory we can as well do piecewise
memory copy analysis and do store/load merging on the tree level.


-- 


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


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

* [Bug tree-optimization/42587] bswap not recognized for memory
  2010-01-03  6:15 [Bug tree-optimization/42587] New: bswap not recognized for union andi-gcc at firstfloor dot org
  2010-01-03 10:58 ` [Bug tree-optimization/42587] bswap not recognized for memory rguenth at gcc dot gnu dot org
@ 2010-01-03 16:01 ` rguenth at gcc dot gnu dot org
  2010-01-03 16:26 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-03 16:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2010-01-03 16:01 -------
SRA here again does somthing stupid:

from

<bb 2>:
  acpi_ut_track_stack_ptr ();
  in.value = value_1(D);
  D.1966_2 = in.bytes[3];
  out.bytes[0] = D.1966_2;
  D.1967_3 = in.bytes[2];
  out.bytes[1] = D.1967_3;
  D.1968_4 = in.bytes[1];
  out.bytes[2] = D.1968_4;
  D.1969_5 = in.bytes[0];
  out.bytes[3] = D.1969_5;
  D.1970_6 = out.value;
  return D.1970_6;

it generates

<bb 2>:
  acpi_ut_track_stack_ptr ();
  in.value = value_1(D);
  in$bytes$0_14 = in.bytes[0];
  in$bytes$1_15 = in.bytes[1];
  in$bytes$2_16 = in.bytes[2];
  in$bytes$3_17 = in.bytes[3];
  D.1966_2 = in$bytes$3_17;
  out.bytes[0] = D.1966_2;
  D.1967_3 = in$bytes$2_16;
  out.bytes[1] = D.1967_3;
  D.1968_4 = in$bytes$1_15;
  out.bytes[2] = D.1968_4;
  D.1969_5 = in$bytes$0_14;
  out.bytes[3] = D.1969_5;
  D.1970_6 = out.value;
  return D.1970_6;

which isn't an improvement and just creates extra temporary registers.


-- 

rguenth at gcc dot gnu dot org changed:

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


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


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

* [Bug tree-optimization/42587] bswap not recognized for memory
  2010-01-03  6:15 [Bug tree-optimization/42587] New: bswap not recognized for union andi-gcc at firstfloor dot org
@ 2010-01-03 10:58 ` rguenth at gcc dot gnu dot org
  2010-01-03 16:01 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-03 10:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-01-03 10:58 -------
Confirmed.

The bswap detection does not work on memory at all but only detects it
on registers.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2010-01-03 10:58:04
               date|                            |
            Summary|bswap not recognized for    |bswap not recognized for
                   |union                       |memory


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


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

end of thread, other threads:[~2021-05-10 12:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-42587-4@http.gcc.gnu.org/bugzilla/>
2012-02-22 13:51 ` [Bug tree-optimization/42587] bswap not recognized for memory xiaoyuanbo at yeah dot net
2021-05-08 13:17 ` peter at cordes dot ca
2021-05-09 21:02 ` andi at firstfloor dot org
2021-05-10 12:21 ` cvs-commit at gcc dot gnu.org
2021-05-10 12:22 ` hjl.tools at gmail dot com
2010-01-03  6:15 [Bug tree-optimization/42587] New: bswap not recognized for union andi-gcc at firstfloor dot org
2010-01-03 10:58 ` [Bug tree-optimization/42587] bswap not recognized for memory rguenth at gcc dot gnu dot org
2010-01-03 16:01 ` rguenth at gcc dot gnu dot org
2010-01-03 16:26 ` rguenth at gcc dot gnu dot org
2010-01-06 14:07 ` jamborm at gcc dot gnu dot org
2010-02-27 20:04 ` rguenth 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).