public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again.
@ 2012-11-02  9:59 dwmw2 at infradead dot org
  2012-11-02 10:46 ` [Bug tree-optimization/55177] " dwmw2 at infradead dot org
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: dwmw2 at infradead dot org @ 2012-11-02  9:59 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55177
           Summary: Missed optimisation: bswap, mask with constant, bswap
                    back again.
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dwmw2@infradead.org


extern int x;

void foo(void)
{
  int a = __builtin_bswap32(x);
  a &= 0x5a5b5c5d;
  x = __builtin_bswap32(a);
}

With GCC 4.7.2 (x86_64 Fedora) this compiles to:
foo:
.LFB0:
    .cfi_startproc
    movl    x(%rip), %eax
    bswap    %eax
    andl    $-1515936861, %eax
    bswap    %eax
    movl    %eax, x(%rip)
    ret
    .cfi_endproc


Surely the actual swap should be optimised out, and the 0x5a5b5c5d constant
mask should be swapped instead so we just load, mask with 0x5d5c5b5a and store
without any runtime swapping?

(See also PR42586 which may be related)


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

* [Bug tree-optimization/55177] Missed optimisation: bswap, mask with constant, bswap back again.
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
@ 2012-11-02 10:46 ` dwmw2 at infradead dot org
  2012-11-02 10:56 ` [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap ebotcazou at gcc dot gnu.org
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: dwmw2 at infradead dot org @ 2012-11-02 10:46 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from David Woodhouse <dwmw2 at infradead dot org> 2012-11-02 10:45:52 UTC ---
We have a similar issue with:

extern void func(void);
int baz(void)
{
    if (__builtin_bswap32(x) & 0x80000)
        func();
}    

baz:
.LFB1:
    .cfi_startproc
    movl    x(%rip), %eax
    bswap    %eax
    testl    $524288, %eax
    jne    .L12
    rep
    ret
…

Again there's no need for a bswap followed by testing with a constant.


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
  2012-11-02 10:46 ` [Bug tree-optimization/55177] " dwmw2 at infradead dot org
@ 2012-11-02 10:56 ` ebotcazou at gcc dot gnu.org
  2012-11-02 17:05 ` dwmw2 at infradead dot org
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-11-02 10:56 UTC (permalink / raw)
  To: gcc-bugs


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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-11-02
                 CC|                            |ebotcazou at gcc dot
                   |                            |gnu.org
          Component|tree-optimization           |rtl-optimization
            Summary|Missed optimisation: bswap, |missed optimizations with
                   |mask with constant, bswap   |__builtin_bswap
                   |back again.                 |
     Ever Confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-11-02 10:56:17 UTC ---
If you don't need to swap, then do not use __builtin_bswap!  The first example
is really dumb.  That being said, the second example has some merit and we
should do something to optimize it at the RTL level.


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
  2012-11-02 10:46 ` [Bug tree-optimization/55177] " dwmw2 at infradead dot org
  2012-11-02 10:56 ` [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap ebotcazou at gcc dot gnu.org
@ 2012-11-02 17:05 ` dwmw2 at infradead dot org
  2012-11-02 17:46 ` ebotcazou at gcc dot gnu.org
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: dwmw2 at infradead dot org @ 2012-11-02 17:05 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from David Woodhouse <dwmw2 at infradead dot org> 2012-11-02 17:05:03 UTC ---
The first example isn't *that* dumb, as a cut-down test case of real code which
may look more complex in reality.

If the real code really *is* as simple as my test case, you're right that
perhaps we *could* optimise it ourselves by eschewing the normal accessor
macros for explicit-endian values, and manually byteswapping the constant
instead.

But really, we shouldn't *have* to. The compiler can see what's happening, and
it can deal with it a whole lot better than we can, especially when it comes to
loads and stores. 

Your argument applies just as well to the second test case. I could just
byteswap the constant instead of the variable. But still I shouldn't have to.


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (2 preceding siblings ...)
  2012-11-02 17:05 ` dwmw2 at infradead dot org
@ 2012-11-02 17:46 ` ebotcazou at gcc dot gnu.org
  2012-11-02 19:42 ` dwmw2 at infradead dot org
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-11-02 17:46 UTC (permalink / raw)
  To: gcc-bugs


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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |ebotcazou at gcc dot
                   |gnu.org                     |gnu.org

--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-11-02 17:45:54 UTC ---
> The first example isn't *that* dumb, as a cut-down test case of real code 
> which may look more complex in reality.

OK, and I can indeed think of some usage patterns in real life.

> If the real code really *is* as simple as my test case, you're right that
> perhaps we *could* optimise it ourselves by eschewing the normal accessor
> macros for explicit-endian values, and manually byteswapping the constant
> instead.
> 
> But really, we shouldn't *have* to. The compiler can see what's happening, and
> it can deal with it a whole lot better than we can, especially when it comes
> to loads and stores. 

Another category would be comparisons then:

int compare1 (int x)
{
  return __builtin_bswap32 (x) == 0xdeadbeef;
}

int compare2 (int x, int y)
{
  return __builtin_bswap32 (x) == __builtin_bswap32 (y);
}

Will have a look shortly.


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (3 preceding siblings ...)
  2012-11-02 17:46 ` ebotcazou at gcc dot gnu.org
@ 2012-11-02 19:42 ` dwmw2 at infradead dot org
  2012-11-02 21:59 ` ebotcazou at gcc dot gnu.org
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: dwmw2 at infradead dot org @ 2012-11-02 19:42 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from David Woodhouse <dwmw2 at infradead dot org> 2012-11-02 19:41:28 UTC ---
Indeed. Bear in mind that sometimes we *hide* the actual variable (by prefixing
its name or putting it in a small struct of its own), just to *force* people to
use the appropriate byte-swapping accessor functions/macros. And with good
reason, because people will often forget to handle the endianness issues
otherwise.

So what you describe as 'really dumb' is actually something that we *force*
people to do. We'd be much worse off without it.

Of course, if we could just mark the variable with __attribute__((bigendian))
then perhaps it would all JustWork™ ... but that's a separate discussion ☹


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (4 preceding siblings ...)
  2012-11-02 19:42 ` dwmw2 at infradead dot org
@ 2012-11-02 21:59 ` ebotcazou at gcc dot gnu.org
  2012-11-08 14:30 ` dwmw2 at infradead dot org
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-11-02 21:59 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-11-02 21:59:27 UTC ---
> So what you describe as 'really dumb' is actually something that we *force*
> people to do. We'd be much worse off without it.

'really dumb' applied only to the example though, not to your design decisions
which are probably reasonable, even if they yield these useless byte-swapping
primitives in some cases.


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (5 preceding siblings ...)
  2012-11-02 21:59 ` ebotcazou at gcc dot gnu.org
@ 2012-11-08 14:30 ` dwmw2 at infradead dot org
  2012-11-08 16:14 ` ebotcazou at gcc dot gnu.org
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: dwmw2 at infradead dot org @ 2012-11-08 14:30 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from David Woodhouse <dwmw2 at infradead dot org> 2012-11-08 14:29:37 UTC ---
Linux kernel patch to use the builtins at
http://marc.info/?l=linux-arch&m=135212414925921&w=2

I think I have the GCC version checks right there, for the availability of the
builtins? That is, __builtin_bswap32() and __builtin_bswap64() since GCC 4.4,
and __builtin_bswap16() since GCC 4.6 on PowerPC or GCC 4.9 on other platforms?


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (6 preceding siblings ...)
  2012-11-08 14:30 ` dwmw2 at infradead dot org
@ 2012-11-08 16:14 ` ebotcazou at gcc dot gnu.org
  2013-03-08 12:12 ` dwmw2 at infradead dot org
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-11-08 16:14 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #8 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-11-08 16:14:23 UTC ---
> I think I have the GCC version checks right there, for the availability of the
> builtins? That is, __builtin_bswap32() and __builtin_bswap64() since GCC 4.4,
> and __builtin_bswap16() since GCC 4.6 on PowerPC or GCC 4.9 on other platforms?

4.8 on other platforms.


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (7 preceding siblings ...)
  2012-11-08 16:14 ` ebotcazou at gcc dot gnu.org
@ 2013-03-08 12:12 ` dwmw2 at infradead dot org
  2013-03-08 15:19 ` pinskia at gcc dot gnu.org
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: dwmw2 at infradead dot org @ 2013-03-08 12:12 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #9 from David Woodhouse <dwmw2 at infradead dot org> 2013-03-08 12:11:24 UTC ---
This is now enabled in the Linux kernel.

Core patch: http://git.kernel.org/linus/cf66bb93 (in v3.8 but does nothing
there)
x86:        http://git.kernel.org/linus/83a57a4d (will be in v3.9)
PowerPC:    http://git.kernel.org/linus/fe3955cb (will be in v3.9)

There's an ARM patch which looks like it missed the boat for 3.9 but should
hopefully be in v3.10: https://lkml.org/lkml/2013/2/22/475

On ARM where we have no load-and-swap or store-and-swap primitives we are
already seeing a tiny win. But fixing up more of the missing optimisations
would be good.


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (8 preceding siblings ...)
  2013-03-08 12:12 ` dwmw2 at infradead dot org
@ 2013-03-08 15:19 ` pinskia at gcc dot gnu.org
  2013-03-09  0:06 ` ebotcazou at gcc dot gnu.org
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-03-08 15:19 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-03-08 15:18:35 UTC ---
Eric,
  I have some patches to improve __builtin_bswap* that I can line up for 4.9. 
Do you mind if I take this bug?  They are located on the pinskia/bytewiseunop
branch in git:
http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/pinskia/bytewiseunop


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

* [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (9 preceding siblings ...)
  2013-03-08 15:19 ` pinskia at gcc dot gnu.org
@ 2013-03-09  0:06 ` ebotcazou at gcc dot gnu.org
  2013-03-09  0:16 ` [Bug tree-optimization/55177] " pinskia at gcc dot gnu.org
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-03-09  0:06 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #11 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2013-03-09 00:05:46 UTC ---
> Eric,
>   I have some patches to improve __builtin_bswap* that I can line up for 4.9. 
> Do you mind if I take this bug?  They are located on the pinskia/bytewiseunop
> branch in git:
> http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/pinskia/bytewiseunop

I have something too (albeit preliminary), but go ahead.


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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (10 preceding siblings ...)
  2013-03-09  0:06 ` ebotcazou at gcc dot gnu.org
@ 2013-03-09  0:16 ` pinskia at gcc dot gnu.org
  2014-04-04 12:40 ` krebbel at gcc dot gnu.org
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-03-09  0:16 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|rtl-optimization            |tree-optimization
         AssignedTo|ebotcazou at gcc dot        |pinskia at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-03-09 00:16:23 UTC ---
Mine for 4.9.  I will also post the bswap for mipsr2 at the same time as I post
these.


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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (11 preceding siblings ...)
  2013-03-09  0:16 ` [Bug tree-optimization/55177] " pinskia at gcc dot gnu.org
@ 2014-04-04 12:40 ` krebbel at gcc dot gnu.org
  2014-11-22 22:11 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: krebbel at gcc dot gnu.org @ 2014-04-04 12:40 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Krebbel <krebbel at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |krebbel at gcc dot gnu.org

--- Comment #13 from Andreas Krebbel <krebbel at gcc dot gnu.org> ---
Is that one fixed with?
2013-05-24  Eric Botcazou  <ebotcazou@adacore.com>

    PR rtl-optimization/55177
    * simplify-rtx.c (simplify_unary_operation_1) <NOT>: Deal with BSWAP.
    (simplify_byte_swapping_operation): New.
    (simplify_binary_operation_1): Call it for AND, IOR and XOR.
    (simplify_relational_operation_1): Deal with BSWAP.


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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (12 preceding siblings ...)
  2014-04-04 12:40 ` krebbel at gcc dot gnu.org
@ 2014-11-22 22:11 ` pinskia at gcc dot gnu.org
  2015-01-23 14:00 ` ubizjak at gmail dot com
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-11-22 22:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The original testcase in comment #0 is still not optimized at the gimple level
due to extra casts.  If I use unsigned instead of int, the testcase is
optimized at the gimple level.


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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (13 preceding siblings ...)
  2014-11-22 22:11 ` pinskia at gcc dot gnu.org
@ 2015-01-23 14:00 ` ubizjak at gmail dot com
  2015-01-23 14:08 ` dwmw2 at infradead dot org
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: ubizjak at gmail dot com @ 2015-01-23 14:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #16 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to David Woodhouse from comment #15)

> {
> 	return (p->data[0] << 24) | (p->data[1] << 16) | (p->data[2] << 8) |
> p->data[1];
> }

p->data[3] ?

> unsigned add(struct pkt *p)
> {
> 	return (p->data[0] << 24) + (p->data[1] << 16) + (p->data[2] << 8) +
> p->data[1];

... and here?
>From gcc-bugs-return-474571-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Jan 23 14:05:45 2015
Return-Path: <gcc-bugs-return-474571-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 17615 invoked by alias); 23 Jan 2015 14:05:44 -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 17470 invoked by uid 48); 23 Jan 2015 14:05:36 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/64741] Incorrect size of UBSan type descriptors
Date: Fri, 23 Jan 2015 14:05:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: sanitizer
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-64741-4-NgIxabfX9S@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64741-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64741-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/msg02565.txt.bz2
Content-length: 459

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The C FE does for vars with flexible array members with initializers:
      DECL_SIZE (decl)
        = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
      DECL_SIZE_UNIT (decl)
        = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type));
So what about doing the same (with type replaced by TREE_TYPE (str))?


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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (14 preceding siblings ...)
  2015-01-23 14:00 ` ubizjak at gmail dot com
@ 2015-01-23 14:08 ` dwmw2 at infradead dot org
  2015-01-23 14:11 ` ubizjak at gmail dot com
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: dwmw2 at infradead dot org @ 2015-01-23 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #17 from David Woodhouse <dwmw2 at infradead dot org> ---
Er, yes. Sorry, I originally tried it with uint16_t but it wasn't even using
movbe for the pointer_abuse() function then, so I made it 32-bit instead.
Badly. Come to think of it, the lack of movbe in the 16-bit pointer_abuse()
case is potentially another bug worth fixing.

Here's the corrected test case.

/* gcc -march=atom -O2 -c load_be.c -Wstrict-aliasing -o- -S */
struct pkt {
    unsigned char data[10];
};

unsigned or(struct pkt *p)
{
    return (p->data[0] << 24) | (p->data[1] << 16) | (p->data[2] << 8) |
p->data[3];
}

unsigned add(struct pkt *p)
{
    return (p->data[0] << 24) + (p->data[1] << 16) + (p->data[2] << 8) +
p->data[3];
}

unsigned pointer_abuse(struct pkt *p)
{
    return __builtin_bswap16(*(unsigned short *)p->data);
}


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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (15 preceding siblings ...)
  2015-01-23 14:08 ` dwmw2 at infradead dot org
@ 2015-01-23 14:11 ` ubizjak at gmail dot com
  2021-11-15  8:30 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: ubizjak at gmail dot com @ 2015-01-23 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #18 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to David Woodhouse from comment #17)

> unsigned or(struct pkt *p)

gcc 5.0 optimizes the above case ...

> unsigned add(struct pkt *p)

... but not this one.  Probably just the case of missing match.pd pattern.
>From gcc-bugs-return-474576-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Jan 23 14:11:46 2015
Return-Path: <gcc-bugs-return-474576-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 23548 invoked by alias); 23 Jan 2015 14:11:45 -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 23045 invoked by uid 48); 23 Jan 2015 14:11:33 -0000
From: "ramana at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug testsuite/62286] [ARM] 4.9 Regression fails for cortex-m3 for vfp-1.c: fmacs, fmscs, fnmacs, fnmscs
Date: Fri, 23 Jan 2015 14:11:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: testsuite
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ramana at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-62286-4-eKJQFEmY4o@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-62286-4@http.gcc.gnu.org/bugzilla/>
References: <bug-62286-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/msg02570.txt.bz2
Content-length: 1636

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

--- Comment #3 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> ---
(In reply to ktkachov from comment #2)
> (In reply to Ramana Radhakrishnan from comment #1)
> > Because the Cortex-M3 doesn't have those instructions ? It's a testism
> > probably fixed by an appropriate dg-options values.
>
> It's not a testism, it's a costs issue.
> The FP instructions are dictated by the -mfpu option that is given
> (-mfpu=vfp is hardcoded in the dg-options here) and in any case Cortex-M3
> should support the vmla instructions as far as I know.
> The RTX costs during combine reject the combination of
>
>          vnmul.f32       s15, s14, s15
>          vsub.f32        s15, s15, s13
>
> into
>          vnmla.f32       s15, s13, s14
>
> for example.
> In particular I think it's the mult_addsub cost. A relevant combine log part
> is:
> Trying 57 -> 58:
> Successfully matched this instruction:
> (set (reg:SF 134 [ D.4322 ])
>     (plus:SF (mult:SF (reg:SF 130 [ D.4322 ])
>             (reg:SF 131 [ D.4322 ]))
>         (reg:SF 133 [ D.4322 ])))
> (plus:SF (mult:SF (reg:SF 130 [ D.4322 ])
>         (reg:SF 131 [ D.4322 ]))
>     (reg:SF 133 [ D.4322 ]))
>
> Hot cost: 24 (final)
> rejecting combination of insns 57 and 58
> original costs 12 + 8 = 20
> replacement cost 24
>
> Is it actually beneficial for Cortex-M3 to split this up?

Well, there is no M3 with an FPU and this whole discussion is moot. I don't
think the costs should be changed for this if they reflect reality i.e. the
cost of a libcall for the multiply and cost of a libcall for addition !




Ramana


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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (16 preceding siblings ...)
  2015-01-23 14:11 ` ubizjak at gmail dot com
@ 2021-11-15  8:30 ` pinskia at gcc dot gnu.org
  2021-11-15  8:35 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-15  8:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55177
Bug 55177 depends on bug 60669, which changed state.

Bug 60669 Summary: VRP misses asserts for some already defined statements
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60669

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

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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (17 preceding siblings ...)
  2021-11-15  8:30 ` pinskia at gcc dot gnu.org
@ 2021-11-15  8:35 ` pinskia at gcc dot gnu.org
  2021-11-15  9:19 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-15  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #22 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #20)
> So the original testcase shows there are missing other bitop related
> optimizations on the tree level and conversions.
> I have two patches which fix the original issue.
> The first patch also fixes:
> unsigned foo(unsigned x, int b)
> {
>   int a = x;
>   a &= b;
>   x = a;
>   x |= b;
>   return x;
> }
> --- CUT ---
> The problem here is:
>   a_3 = (int) x_2(D);
>   a_5 = a_3 & b_4(D);
>   x_6 = (unsigned int) a_5;
> 
> is not optimized to:
>   _7 = (unsigned int) b_4(D);
>   x_6 = _6 & x_2(D);
> 
> Which shows up in testcase in comment #0:
>   _2 = __builtin_bswap32 (x.0_1);
>   a_6 = (int) _2;
>   a_7 = a_6 & 1515936861;
>   a.1_3 = (unsigned int) a_7;
>   _4 = __builtin_bswap32 (a.1_3);
> 
> Fixing the bitop with convert, we get rid of the two byteswaps in comment #0.

That I happened to file as PR 103228 a few days ago but only on accident while
looking into a different issue.  Since PR 60669 is now fixed, I will test my
original patch to fix this.

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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (18 preceding siblings ...)
  2021-11-15  8:35 ` pinskia at gcc dot gnu.org
@ 2021-11-15  9:19 ` pinskia at gcc dot gnu.org
  2021-11-17 23:40 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-15  9:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=94718

--- Comment #23 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #20)
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 363006e28fd..d0258a19534 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1393,7 +1393,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>            /* Or if the precision of TO is not the same as the precision
>               of its mode.  */
>            || !type_has_mode_precision_p (type)))
> -   (convert (bitop @0 (convert @1))))))
> +   (convert (bitop @0 (convert @1)))))
> + (simplify
> +  (convert (bitop:c (nop_convert @0) @1))
> +  (if (tree_nop_conversion_p (type, TREE_TYPE (@1))
> +       && types_match (type, TREE_TYPE (@0)))
> +   (bitop @0 (convert @1)))))
> 
>  (for bitop (bit_and bit_ior)
>       rbitop (bit_ior bit_and)

Note this part of the patch went in as part of PR 94718.

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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (19 preceding siblings ...)
  2021-11-15  9:19 ` pinskia at gcc dot gnu.org
@ 2021-11-17 23:40 ` cvs-commit at gcc dot gnu.org
  2021-11-17 23:40 ` pinskia at gcc dot gnu.org
  2021-11-17 23:41 ` pinskia at gcc dot gnu.org
  22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-17 23:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #24 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:32221357007666124409ec3ee0d3a1cf263ebc9e

commit r12-5358-g32221357007666124409ec3ee0d3a1cf263ebc9e
Author: Andrew Pinski <apinski@marvell.com>
Date:   Mon Nov 15 09:31:20 2021 +0000

    Fix PR tree-optimization/103228 and 103228: folding of (type) X op CST
where type is a nop convert

    Currently we fold (type) X op CST into (type) (X op ((type-x) CST)) when
the conversion widens
    but not when the conversion is a nop. For the same reason why we move the
widening conversion
    (the possibility of removing an extra conversion), we should do the same if
the conversion is a
    nop.

    Committed as approved with the comment change.

            PR tree-optimization/103228
            PR tree-optimization/55177

    gcc/ChangeLog:

            * match.pd ((type) X bitop CST): Also do this
            transformation for nop conversions.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/pr103228-1.c: New test.
            * gcc.dg/tree-ssa/pr55177-1.c: New test.

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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (20 preceding siblings ...)
  2021-11-17 23:40 ` cvs-commit at gcc dot gnu.org
@ 2021-11-17 23:40 ` pinskia at gcc dot gnu.org
  2021-11-17 23:41 ` pinskia at gcc dot gnu.org
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-17 23:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55177
Bug 55177 depends on bug 103228, which changed state.

Bug 103228 Summary: [9/10/11/12 Regression] missed optimization with |^ at the gimple level
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103228

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

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

* [Bug tree-optimization/55177] missed optimizations with __builtin_bswap
  2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
                   ` (21 preceding siblings ...)
  2021-11-17 23:40 ` pinskia at gcc dot gnu.org
@ 2021-11-17 23:41 ` pinskia at gcc dot gnu.org
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-17 23:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |12.0

--- Comment #25 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed fully in GCC 12.

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

end of thread, other threads:[~2021-11-17 23:41 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-02  9:59 [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again dwmw2 at infradead dot org
2012-11-02 10:46 ` [Bug tree-optimization/55177] " dwmw2 at infradead dot org
2012-11-02 10:56 ` [Bug rtl-optimization/55177] missed optimizations with __builtin_bswap ebotcazou at gcc dot gnu.org
2012-11-02 17:05 ` dwmw2 at infradead dot org
2012-11-02 17:46 ` ebotcazou at gcc dot gnu.org
2012-11-02 19:42 ` dwmw2 at infradead dot org
2012-11-02 21:59 ` ebotcazou at gcc dot gnu.org
2012-11-08 14:30 ` dwmw2 at infradead dot org
2012-11-08 16:14 ` ebotcazou at gcc dot gnu.org
2013-03-08 12:12 ` dwmw2 at infradead dot org
2013-03-08 15:19 ` pinskia at gcc dot gnu.org
2013-03-09  0:06 ` ebotcazou at gcc dot gnu.org
2013-03-09  0:16 ` [Bug tree-optimization/55177] " pinskia at gcc dot gnu.org
2014-04-04 12:40 ` krebbel at gcc dot gnu.org
2014-11-22 22:11 ` pinskia at gcc dot gnu.org
2015-01-23 14:00 ` ubizjak at gmail dot com
2015-01-23 14:08 ` dwmw2 at infradead dot org
2015-01-23 14:11 ` ubizjak at gmail dot com
2021-11-15  8:30 ` pinskia at gcc dot gnu.org
2021-11-15  8:35 ` pinskia at gcc dot gnu.org
2021-11-15  9:19 ` pinskia at gcc dot gnu.org
2021-11-17 23:40 ` cvs-commit at gcc dot gnu.org
2021-11-17 23:40 ` pinskia at gcc dot gnu.org
2021-11-17 23:41 ` 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).