public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/65768] New: sub-optimimal code for constant Uses in loop
@ 2015-04-15  7:09 kugan at gcc dot gnu.org
  2015-04-15  7:12 ` [Bug target/65768] " kugan at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: kugan at gcc dot gnu.org @ 2015-04-15  7:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65768
           Summary: sub-optimimal code for constant Uses in loop
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kugan at gcc dot gnu.org

#include <stdint.h>
void maskdata(int32_t * data, unsigned int len)
{
  const int32_t mask = 0x00ff00ff;
  for (int i=len; i-- > 0 ;) {
      data[i] &= mask;
  }
}

Is producing the following with arm-none-linux-gnueabi-gcc for -O2:

maskdata:
    @ args = 0, pretend = 0, frame = 0
    @ frame_needed = 0, uses_anonymous_args = 0
    @ link register save eliminated.
    cmp    r1, #0
    bxle    lr
    add    r1, r0, r1, lsl #2
.L3:
    ldr    r3, [r1, #-4]!
    cmp    r1, r0
    bic    r3, r3, #-16777216
    bic    r3, r3, #65280
    str    r3, [r1]
    bne    .L3
    bx    lr
    .size    maskdata, .-maskdata
    .ident    "GCC: (GNU) 5.0.0 20150409 (experimental)"
    .section    .note.GNU-stack,"",%progbits


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

* [Bug target/65768] sub-optimimal code for constant Uses in loop
  2015-04-15  7:09 [Bug target/65768] New: sub-optimimal code for constant Uses in loop kugan at gcc dot gnu.org
@ 2015-04-15  7:12 ` kugan at gcc dot gnu.org
  2015-05-16  9:36 ` kugan at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kugan at gcc dot gnu.org @ 2015-04-15  7:12 UTC (permalink / raw)
  To: gcc-bugs

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

kugan at gcc dot gnu.org changed:

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

--- Comment #1 from kugan at gcc dot gnu.org ---
Zhenqiang posted following patches in this regard.

[PATCH, cprop] Check rtx_cost when propagating constant
https://gcc.gnu.org/ml/gcc-patches/2014-06/msg01321.html

[PATCH, ARM] Keep constants in register when expanding
https://gcc.gnu.org/ml/gcc-patches/2014-08/msg00325.html


Note that, Zhenqiang's patch still will not work for 0x00ff00ff and works only
for 0xfe00ff (as used in the testcase for the above patch).

For the case of 0x00ff00ff, this constant is splt by the backend during expand
as:

(insn 52 51 53 (set (reg:SI 154)
        (const_int 255 [0xff])) const1.c:6 -1
     (nil))

(insn 53 52 54 (set (zero_extract:SI (reg:SI 154)
            (const_int 16 [0x10])
            (const_int 16 [0x10]))
        (const_int 255 [0xff])) const1.c:6 -1
     (nil))

The ZERO_EXTRACT has 255 as the src (from 0xff00ff) which (same constant 255)
is also set in the same register in the previous instruction. So, during CSE,
it
detects that they are same and using r154 when simplifying ZERO_EXTRACT with
the
constant. But in the case of, 0xfe00ff, theses two constants are different (255
and 254) hence CSE simplifies it back to  0xfe00ff. RTL loop invariant code
motion can now move it out. However, if the constant is still split and are
constructed with two instructions, it will not be able to move it out.

I believe the fix is to delay splitting. i.e., do not split for SET as well
during expand.

CSE simplifying ZERO_EXTRACT is probably not wise as well because it is doing
this without consulting the back-end cost.


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

* [Bug target/65768] sub-optimimal code for constant Uses in loop
  2015-04-15  7:09 [Bug target/65768] New: sub-optimimal code for constant Uses in loop kugan at gcc dot gnu.org
  2015-04-15  7:12 ` [Bug target/65768] " kugan at gcc dot gnu.org
@ 2015-05-16  9:36 ` kugan at gcc dot gnu.org
  2015-06-02 22:53 ` kugan at gcc dot gnu.org
  2015-06-02 23:53 ` kugan at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: kugan at gcc dot gnu.org @ 2015-05-16  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from kugan at gcc dot gnu.org ---
Author: kugan
Date: Sat May 16 09:35:52 2015
New Revision: 223235

URL: https://gcc.gnu.org/viewcvs?rev=223235&root=gcc&view=rev
Log:
gcc/ChangeLog:

2015-05-16  Kugan Vivekanandarajah  <kuganv@linaro.org>
            Zhenqiang Chen  <zhenqiang.chen@linaro.org>

        PR target/65768
        * config/arm/arm.h (DONT_EARLY_SPLIT_CONSTANT): New macro.
        * config/arm/arm.md (subsi3, andsi3, iorsi3, xorsi3, movsi): Keep some
         large constants in register instead of splitting them.

gcc/testsuite/ChangeLog:

2015-05-16  Kugan Vivekanandarajah  <kuganv@linaro.org>
            Zhenqiang Chen  <zhenqiang.chen@linaro.org>

        PR target/65768
        * gcc.target/arm/maskdata.c: New test.


Added:
    trunk/gcc/testsuite/gcc.target/arm/maskdata.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.h
    trunk/gcc/config/arm/arm.md
    trunk/gcc/testsuite/ChangeLog


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

* [Bug target/65768] sub-optimimal code for constant Uses in loop
  2015-04-15  7:09 [Bug target/65768] New: sub-optimimal code for constant Uses in loop kugan at gcc dot gnu.org
  2015-04-15  7:12 ` [Bug target/65768] " kugan at gcc dot gnu.org
  2015-05-16  9:36 ` kugan at gcc dot gnu.org
@ 2015-06-02 22:53 ` kugan at gcc dot gnu.org
  2015-06-02 23:53 ` kugan at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: kugan at gcc dot gnu.org @ 2015-06-02 22:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from kugan at gcc dot gnu.org ---
Author: kugan
Date: Tue Jun  2 22:53:15 2015
New Revision: 224048

URL: https://gcc.gnu.org/viewcvs?rev=224048&root=gcc&view=rev
Log:
gcc/ChangeLog:

2015-06-03  Kugan Vivekanandarajah  <kuganv@linaro.org>
            Zhenqiang Chen  <zhenqiang.chen@linaro.org>

        PR target/65768
        * cprop.c (try_replace_reg): Check cost of constants before
propagating.


gcc/testsuite/ChangeLog:

2015-06-03  Kugan Vivekanandarajah  <kuganv@linaro.org>

        PR target/65768
        * gcc.target/arm/maskdata.c: Remove -fno-gcse.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cprop.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/arm/maskdata.c


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

* [Bug target/65768] sub-optimimal code for constant Uses in loop
  2015-04-15  7:09 [Bug target/65768] New: sub-optimimal code for constant Uses in loop kugan at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2015-06-02 22:53 ` kugan at gcc dot gnu.org
@ 2015-06-02 23:53 ` kugan at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: kugan at gcc dot gnu.org @ 2015-06-02 23:53 UTC (permalink / raw)
  To: gcc-bugs

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

kugan at gcc dot gnu.org changed:

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

--- Comment #4 from kugan at gcc dot gnu.org ---
Fixed now.


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

end of thread, other threads:[~2015-06-02 23:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-15  7:09 [Bug target/65768] New: sub-optimimal code for constant Uses in loop kugan at gcc dot gnu.org
2015-04-15  7:12 ` [Bug target/65768] " kugan at gcc dot gnu.org
2015-05-16  9:36 ` kugan at gcc dot gnu.org
2015-06-02 22:53 ` kugan at gcc dot gnu.org
2015-06-02 23:53 ` kugan 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).