public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/56096] New: Bad code generated for conditional shift
@ 2013-01-24  6:47 tilman@code-monkey.de
  2013-01-24  8:55 ` [Bug target/56096] " mikpe at it dot uu.se
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: tilman@code-monkey.de @ 2013-01-24  6:47 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56096
           Summary: Bad code generated for conditional shift
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tilman@code-monkey.de


Compiling this snippet

unsigned f1 (unsigned x, unsigned m)
{
    x >>= ((m & 0x008080) ? 8 : 0);
    return x;
}

with gcc 4.7.2 gives this code for ARMv5:

$ armv5tel-softfloat-linux-gnueabi-gcc -O2 -S -o- f.c
[...]
    ldr    r3, .L4
    and    r3, r1, r3
    cmp    r3, #0
    movne    r3, #8           @ XXX
    moveq    r3, #0           @ XXX
    mov    r0, r0, lsr r3   @ XXX
    bx    lr
[...]

Those three mov instructions are clearly sub-optimal.

Replacing the ternary operator with an if-statement gives the expected code
sequence:

unsigned f1 (unsigned x, unsigned m)
{
    if (m & 0x008080)
        x >>= 8;

    return x;
}

-> 
    ldr    r3, .L6
    and    r3, r1, r3
    cmp    r3, #0
    movne    r0, r0, lsr #8
    bx    lr

ie we saved two mov instructions.


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

* [Bug target/56096] Bad code generated for conditional shift
  2013-01-24  6:47 [Bug target/56096] New: Bad code generated for conditional shift tilman@code-monkey.de
@ 2013-01-24  8:55 ` mikpe at it dot uu.se
  2013-03-05  9:06 ` [Bug tree-optimization/56096] Sub-optimal " rearnsha at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mikpe at it dot uu.se @ 2013-01-24  8:55 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2013-01-24 08:54:44 UTC ---
"Bad" is ambiguous, it could mean "sub-optimal" or it could mean "incorrect" or
"wrong".  In this case it means "sub-optimal", please change the PR summary to
reflect that.


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

* [Bug tree-optimization/56096] Sub-optimal code generated for conditional shift
  2013-01-24  6:47 [Bug target/56096] New: Bad code generated for conditional shift tilman@code-monkey.de
  2013-01-24  8:55 ` [Bug target/56096] " mikpe at it dot uu.se
@ 2013-03-05  9:06 ` rearnsha at gcc dot gnu.org
  2021-07-25  2:08 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2013-03-05  9:06 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-03-05
          Component|target                      |tree-optimization
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Earnshaw <rearnsha at gcc dot gnu.org> 2013-03-05 09:06:22 UTC ---
Confirmed.  This is a generic problem with the way the tree optimizers and
expand work.


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

* [Bug tree-optimization/56096] Sub-optimal code generated for conditional shift
  2013-01-24  6:47 [Bug target/56096] New: Bad code generated for conditional shift tilman@code-monkey.de
  2013-01-24  8:55 ` [Bug target/56096] " mikpe at it dot uu.se
  2013-03-05  9:06 ` [Bug tree-optimization/56096] Sub-optimal " rearnsha at gcc dot gnu.org
@ 2021-07-25  2:08 ` pinskia at gcc dot gnu.org
  2023-08-05  3:49 ` pinskia at gcc dot gnu.org
  2023-08-05  3:54 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-25  2:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|armv5                       |
   Last reconfirmed|2013-03-05 00:00:00         |2021-7-24
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/56096] Sub-optimal code generated for conditional shift
  2013-01-24  6:47 [Bug target/56096] New: Bad code generated for conditional shift tilman@code-monkey.de
                   ` (2 preceding siblings ...)
  2021-07-25  2:08 ` pinskia at gcc dot gnu.org
@ 2023-08-05  3:49 ` pinskia at gcc dot gnu.org
  2023-08-05  3:54 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-05  3:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC 7-10 produced:
        movw    r3, #32896
        tst     r1, r3
        it      ne
        lsrne   r0, r0, #8
        bx      lr

But GCC 11 produces:
        movw    r3, #32896
        tst     r1, r3
        ite     ne
        movne   r3, #1
        moveq   r3, #0
        lsls    r3, r3, #3
        lsrs    r0, r0, r3

Which is definitely worse.

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

* [Bug tree-optimization/56096] Sub-optimal code generated for conditional shift
  2013-01-24  6:47 [Bug target/56096] New: Bad code generated for conditional shift tilman@code-monkey.de
                   ` (3 preceding siblings ...)
  2023-08-05  3:49 ` pinskia at gcc dot gnu.org
@ 2023-08-05  3:54 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-05  3:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think one way to improve the constant forming is during isel if we have
condition exec (e.g. arm or ia64) we should transform:
  _7 = _1 != 0;
  _8 = (int) _7;
  _9 = _8 << 3;
to:
_9 = _1 ? 8 : 0;
That will at least fix this part:
        movne   r3, #1
        moveq   r3, #0
        lsls    r3, r3, #3

To fix the other part, I don't know ...

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

end of thread, other threads:[~2023-08-05  3:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-24  6:47 [Bug target/56096] New: Bad code generated for conditional shift tilman@code-monkey.de
2013-01-24  8:55 ` [Bug target/56096] " mikpe at it dot uu.se
2013-03-05  9:06 ` [Bug tree-optimization/56096] Sub-optimal " rearnsha at gcc dot gnu.org
2021-07-25  2:08 ` pinskia at gcc dot gnu.org
2023-08-05  3:49 ` pinskia at gcc dot gnu.org
2023-08-05  3:54 ` 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).