public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/45176]  New: restrict qualifier is not used in a manually unrolled loop
@ 2010-08-04  9:06 bmei at broadcom dot com
  2010-08-04  9:20 ` [Bug c/45176] " rguenth at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: bmei at broadcom dot com @ 2010-08-04  9:06 UTC (permalink / raw)
  To: gcc-bugs

void foo (int * restrict a, int * restrict b, int * restrict c)
{
   int i;
   for(i = 0; i < 100; i+=4)
     {
       a[i] = b[i] * c[i];
       a[i+1] = b[i+1] * c[i+1];
       a[i+2] = b[i+2] * c[i+2];
       a[i+3] = b[i+3] * c[i+3];
     }
}   

Trunk x86-64 compiler (162821) produces code that later load instructions are
not scheduled before the previous store instructions as expected. Clearly,
restrict qualifier is not used here. 

 ~/work/install-x86/bin/gcc tst3.c -O2 -S -std=c99 -da -fschedule-insns
-frename-registers
.L2:
        movl    (%rdx,%rax), %r10d
        imull   (%rsi,%rax), %r10d
        movl    %r10d, (%rdi,%rax)
        movl    4(%rdx,%rax), %r9d
        imull   4(%rsi,%rax), %r9d
        movl    %r9d, 4(%rdi,%rax)
        movl    8(%rdx,%rax), %r8d
        imull   8(%rsi,%rax), %r8d
        movl    %r8d, 8(%rdi,%rax)
        movl    12(%rdx,%rax), %ecx
        imull   12(%rsi,%rax), %ecx
        movl    %ecx, 12(%rdi,%rax)
        addq    $16, %rax
        cmpq    $400, %rax

Richard has a patch and it seems to work for this example. 
Index: expr.c
===================================================================
--- expr.c      (revision 162841)
+++ expr.c      (working copy)
@@ -8665,7 +8665,7 @@ expand_expr_real_1 (tree exp, rtx target
        set_mem_addr_space (temp, as);
        base = get_base_address (TMR_ORIGINAL (exp));
        if (base
-           && INDIRECT_REF_P (base)
+           && (INDIRECT_REF_P (base) || TREE_CODE (base) == MEM_REF)
            && TMR_BASE (exp)
            && TREE_CODE (TMR_BASE (exp)) == SSA_NAME
            && POINTER_TYPE_P (TREE_TYPE (TMR_BASE (exp))))

The code generated:
.L2:
        movl    (%rdx,%rax), %r10d
        movl    4(%rdx,%rax), %r9d
        imull   (%rsi,%rax), %r10d
        imull   4(%rsi,%rax), %r9d
        movl    8(%rdx,%rax), %r8d
        movl    12(%rdx,%rax), %ecx
        imull   8(%rsi,%rax), %r8d
        imull   12(%rsi,%rax), %ecx
        movl    %r10d, (%rdi,%rax)
        movl    %r9d, 4(%rdi,%rax)
        movl    %r8d, 8(%rdi,%rax)
        movl    %ecx, 12(%rdi,%rax)
        addq    $16, %rax
        cmpq    $400, %rax
        jne     .L2


-- 
           Summary: restrict qualifier is not used in a manually unrolled
                    loop
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bmei at broadcom dot com


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


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

end of thread, other threads:[~2010-08-05 13:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-04  9:06 [Bug c/45176] New: restrict qualifier is not used in a manually unrolled loop bmei at broadcom dot com
2010-08-04  9:20 ` [Bug c/45176] " rguenth at gcc dot gnu dot org
2010-08-04 11:09 ` rguenth at gcc dot gnu dot org
2010-08-04 11:10 ` rguenth at gcc dot gnu dot org
2010-08-05 13:41 ` siarhei dot siamashka at gmail dot com
2010-08-05 13:44 ` bmei at broadcom dot com

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).