public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/43224]  New: Constant load not raised out of loop
@ 2010-03-02  3:44 astrange at ithinksw dot com
  2010-03-02  3:45 ` [Bug tree-optimization/43224] " astrange at ithinksw dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: astrange at ithinksw dot com @ 2010-03-02  3:44 UTC (permalink / raw)
  To: gcc-bugs

Source:
#include <string.h>

void dequant_lsps(double *lsps, int num,
                  const unsigned short *values,
                  int n_stages, const unsigned char * __restrict table,
                  const double * __restrict mul_q, const double * __restrict
base_q)
{
    const unsigned char *t_off = &table[values[0] * num];
    int m;

    memset(lsps, 0, num * sizeof(*lsps));

        for (m = 0; m < num; m++)
        lsps[m] += base_q[0] + mul_q[0] * t_off[m];
}

> /usr/local/gcc45/bin/gcc -O3 -S base_lsp.c

The inner loop:
L3:
        movzbl  (%r15), %edx
        incq    %r15
        cvtsi2sd        %edx, %xmm0
        mulsd   0(%r13), %xmm0 <- constant (and "0" prefix)
        addsd   (%r14), %xmm0 <- constant
        addsd   (%rbx,%rax), %xmm0
        movsd   %xmm0, (%rbx,%rax)
        addq    $8, %rax
        cmpq    %rcx, %rax
        jne     L3

Rest of the output attached.
base_q and mul_q should be loaded outside of the loop but aren't. I added
__restrict to base_q/mul_q/table, but it didn't affect it.
Code is reduced from FFmpeg WMA Voice decoder.


-- 
           Summary: Constant load not raised out of loop
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: astrange at ithinksw dot com
  GCC host triplet: x86_64-apple-darwin10.2.0


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


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

* [Bug tree-optimization/43224] Constant load not raised out of loop
  2010-03-02  3:44 [Bug tree-optimization/43224] New: Constant load not raised out of loop astrange at ithinksw dot com
@ 2010-03-02  3:45 ` astrange at ithinksw dot com
  2010-03-02  3:53 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: astrange at ithinksw dot com @ 2010-03-02  3:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from astrange at ithinksw dot com  2010-03-02 03:45 -------
Created an attachment (id=20002)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20002&action=view)
x86-64 asm output


-- 


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


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

* [Bug tree-optimization/43224] Constant load not raised out of loop
  2010-03-02  3:44 [Bug tree-optimization/43224] New: Constant load not raised out of loop astrange at ithinksw dot com
  2010-03-02  3:45 ` [Bug tree-optimization/43224] " astrange at ithinksw dot com
@ 2010-03-02  3:53 ` pinskia at gcc dot gnu dot org
  2010-03-02  3:57 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-03-02  3:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2010-03-02 03:53 -------
I think what GCC is doing is correct as lsps could conflict with mul_q and
base_q as lsps is not marked as restrict.
Doing this:
#include <string.h>

void dequant_lsps(double *__restrict lsps, int num,
                 const unsigned short *values,
                 int n_stages, const unsigned char * __restrict table,
                 const double * __restrict mul_q, const double * __restrict
base_q)
{
   const unsigned char * __restrict t_off = &table[values[0] * num];
   int m;

   memset(lsps, 0, num * sizeof(*lsps));

       for (m = 0; m < num; m++)
       lsps[m] += base_q[0] + mul_q[0] * t_off[m];
}

Allows GCC to optimize those loads away.


-- 


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


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

* [Bug tree-optimization/43224] Constant load not raised out of loop
  2010-03-02  3:44 [Bug tree-optimization/43224] New: Constant load not raised out of loop astrange at ithinksw dot com
  2010-03-02  3:45 ` [Bug tree-optimization/43224] " astrange at ithinksw dot com
  2010-03-02  3:53 ` pinskia at gcc dot gnu dot org
@ 2010-03-02  3:57 ` pinskia at gcc dot gnu dot org
  2010-03-02  4:00 ` astrange at ithinksw dot com
  2010-03-02 12:19 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-03-02  3:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2010-03-02 03:56 -------
In fact that is correct, see PR 14192 for the reasons why.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug tree-optimization/43224] Constant load not raised out of loop
  2010-03-02  3:44 [Bug tree-optimization/43224] New: Constant load not raised out of loop astrange at ithinksw dot com
                   ` (2 preceding siblings ...)
  2010-03-02  3:57 ` pinskia at gcc dot gnu dot org
@ 2010-03-02  4:00 ` astrange at ithinksw dot com
  2010-03-02 12:19 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: astrange at ithinksw dot com @ 2010-03-02  4:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from astrange at ithinksw dot com  2010-03-02 04:00 -------
Is it possible for aliased writes to affect a const pointer? I was assuming
that it wasn't.


-- 


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


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

* [Bug tree-optimization/43224] Constant load not raised out of loop
  2010-03-02  3:44 [Bug tree-optimization/43224] New: Constant load not raised out of loop astrange at ithinksw dot com
                   ` (3 preceding siblings ...)
  2010-03-02  4:00 ` astrange at ithinksw dot com
@ 2010-03-02 12:19 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-02 12:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2010-03-02 12:18 -------
(In reply to comment #4)
> Is it possible for aliased writes to affect a const pointer? I was assuming
> that it wasn't.

Yes, it is possible.  C const qualification doesn't add any useful
information for a compiler (well, const qualification on types).


-- 


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


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

end of thread, other threads:[~2010-03-02 12:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-02  3:44 [Bug tree-optimization/43224] New: Constant load not raised out of loop astrange at ithinksw dot com
2010-03-02  3:45 ` [Bug tree-optimization/43224] " astrange at ithinksw dot com
2010-03-02  3:53 ` pinskia at gcc dot gnu dot org
2010-03-02  3:57 ` pinskia at gcc dot gnu dot org
2010-03-02  4:00 ` astrange at ithinksw dot com
2010-03-02 12:19 ` 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).