public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/101226] New: Suboptimal codegen for >>/>>>
@ 2021-06-26 16:14 maxsamukha at gmail dot com
  2021-07-16 22:51 ` [Bug tree-optimization/101226] " pinskia at gcc dot gnu.org
  2023-05-02  4:06 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: maxsamukha at gmail dot com @ 2021-06-26 16:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101226
           Summary: Suboptimal codegen for >>/>>>
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: maxsamukha at gmail dot com
  Target Milestone: ---
            Target: AVR

example.d:

void f1()
{
    __gshared ubyte value;
    value >>>= 5;
}

void f2()
{
    __gshared ubyte value;
    value = value >>> 5;
}

----
avr-gcc -fno-druntime -O3 example.d:

example.f1():
        lds r24,example.f1().value
        swap r24
        lsr r24
        andi r24,lo8(7)
        sts example.f1().value,r24
        ret
example.f2():
        lds r24,example.f2().value
        ldi r25,0
        ldi r27,0
        ldi r26,0
        ldi r18,5
        1:
        lsr r27
        ror r26
        ror r25
        ror r24
        dec r18
        brne 1b
        sts example.f2().value,r24
        ret

The compiler apparently fails to optimize out the integer promotion for >>> in
f2 and produces inefficient machine code.

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

* [Bug tree-optimization/101226] Suboptimal codegen for >>/>>>
  2021-06-26 16:14 [Bug d/101226] New: Suboptimal codegen for >>/>>> maxsamukha at gmail dot com
@ 2021-07-16 22:51 ` pinskia at gcc dot gnu.org
  2023-05-02  4:06 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-16 22:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
          Component|d                           |tree-optimization
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-07-16
           Keywords|                            |missed-optimization
                 CC|                            |pinskia at gcc dot gnu.org
           Assignee|ibuclaw at gdcproject dot org      |unassigned at gcc dot gnu.org

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  _2 = (uint) value.1_1;
  _3 = _2 >> 5;
  _4 = (ubyte) _3;

Right this could be optimized at the tree level to be :
  _4 = value.1_1 >> 5;


Something like this for match.pd (note this is not fully correct just close
enough for someone else to start):
(simplify
 (convert (shift (convert@0 @1) INTEGER_CST@2))
 (if (type == TREE_TYPE (@0) && TYPE_SIGN (TREE_TYPE(@0) == TYPE_SIGN (type))
  (if (@2 >= bitsintype(type))
   ({build_zero_cst (type);})
   (shift @1 @2))))

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

* [Bug tree-optimization/101226] Suboptimal codegen for >>/>>>
  2021-06-26 16:14 [Bug d/101226] New: Suboptimal codegen for >>/>>> maxsamukha at gmail dot com
  2021-07-16 22:51 ` [Bug tree-optimization/101226] " pinskia at gcc dot gnu.org
@ 2023-05-02  4:06 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-02  4:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a C/C++ example:
typedef unsigned char ubyte;
void f1()
{
    extern ubyte value;
    unsigned int t = value;
    t >>= 5;
    value = t;
}

void f2()
{
    extern ubyte value;
    value = value >> 5;
}

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

end of thread, other threads:[~2023-05-02  4:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-26 16:14 [Bug d/101226] New: Suboptimal codegen for >>/>>> maxsamukha at gmail dot com
2021-07-16 22:51 ` [Bug tree-optimization/101226] " pinskia at gcc dot gnu.org
2023-05-02  4:06 ` 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).