public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/48885] New: missed optimization with restrict qualifier?
@ 2011-05-05 12:56 jerome.frgacic at yahoo dot fr
  2011-05-05 14:54 ` [Bug c/48885] " rguenth at gcc dot gnu.org
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: jerome.frgacic at yahoo dot fr @ 2011-05-05 12:56 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: missed optimization with restrict qualifier?
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jerome.frgacic@yahoo.fr


Hello,

I recently experiment the optimizations obtained by using the restrict
qualifier introduced by the C99 standard. In this purpose, I used this trivial
exemple:

#include <stdio.h>
#include <stdlib.h>


void
test (int *a, int *b, int * restrict v)
{
    *a = *v;
    *b = *v;
}


int
main (void)
{
    int a;
    int b;
    int v = 10;

    test (&a, &b, &v);
    return EXIT_SUCCESS;
}

If i compiled it with the -S and -O2 options, I obtained for the "test"
function:

movl    (%rdx), %eax
movl    %eax, (%rdi)
movl    (%rdx), %eax
movl    %eax, (%rsi)

However, if I had correctly understand the meaning of a restrict pointer, we
can normally expect in the "test" function that the object pointed to by "v"
cannot be changed through "a" or "b"; and therefore perform only one load, like
this:

movl    (%rdx), %eax
movl    %eax, (%rdi)
movl    %eax, (%rsi)

But, the optimization only operate if all the pointers are restrict qualified.
Why?


PS: I compile with GCC 4.6 (Debian amd64 unstable package).


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

end of thread, other threads:[~2015-09-28  9:38 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-05 12:56 [Bug c/48885] New: missed optimization with restrict qualifier? jerome.frgacic at yahoo dot fr
2011-05-05 14:54 ` [Bug c/48885] " rguenth at gcc dot gnu.org
2011-05-05 21:25 ` marc.glisse at normalesup dot org
2013-08-28 14:02 ` paulo@matos-sorge.com
2013-10-15 21:24 ` glisse at gcc dot gnu.org
2013-10-16  9:42 ` paulo@matos-sorge.com
2013-10-16 11:36 ` glisse at gcc dot gnu.org
2013-10-16 13:21 ` paulo@matos-sorge.com
2013-10-16 13:35 ` glisse at gcc dot gnu.org
2013-10-16 18:55 ` glisse at gcc dot gnu.org
2015-09-22 21:46 ` vries at gcc dot gnu.org
2015-09-23 11:24 ` rguenth at gcc dot gnu.org
2015-09-23 12:16 ` vries at gcc dot gnu.org
2015-09-23 12:22 ` rguenther at suse dot de
2015-09-23 14:28 ` vries at gcc dot gnu.org
2015-09-24  7:32 ` rguenth at gcc dot gnu.org
2015-09-24  7:35 ` rguenth at gcc dot gnu.org
2015-09-24  7:36 ` rguenth at gcc dot gnu.org
2015-09-25  7:39 ` vries at gcc dot gnu.org
2015-09-25  7:47 ` rguenther at suse dot de
2015-09-25  7:56 ` glisse at gcc dot gnu.org
2015-09-25 10:30 ` vries at gcc dot gnu.org
2015-09-25 17:02 ` joseph at codesourcery dot com
2015-09-28  9:38 ` vries 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).