From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6849 invoked by alias); 2 Oct 2011 00:59:00 -0000 Received: (qmail 6839 invoked by uid 22791); 2 Oct 2011 00:59:00 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 02 Oct 2011 00:58:44 +0000 Received: by wyh5 with SMTP id 5so2399582wyh.20 for ; Sat, 01 Oct 2011 17:58:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.145.195 with SMTP id e3mr1263525wbv.80.1317517123399; Sat, 01 Oct 2011 17:58:43 -0700 (PDT) Received: by 10.180.106.100 with HTTP; Sat, 1 Oct 2011 17:58:43 -0700 (PDT) Date: Sun, 02 Oct 2011 00:59:00 -0000 Message-ID: Subject: Suboptimal __restrict optimization? From: Ulf Magnusson To: gcc@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg00006.txt.bz2 Hi, Given the code class C { void f(int *p); int q; }; void C::f(int * __restrict p) __restrict { q += 10; *p = 7; q += 10; } g++ 4.5.2 with -O3 generates the following for C::f() (prologue and epilogue omitted): mov 0x8(%ebp),%eax // eax = this (= &q) mov 0xc(%ebp),%ecx // ecx = p mov (%eax),%edx // edx = q movl $0x7,(%ecx) // *p = 7 add $0x14,%edx // q += 20 mov %edx,(%eax) // save q If C::f() is rearranged as void C::f(int * __restrict p) __restrict { *p = 7; q += 10; q += 10; } the following is generated instead: mov 0x8(%ebp),%eax // eax = this (= &q) mov 0xc(%ebp),%edx // edx = p movl $0x7,(%edx) // *p = 7 addl $0x14,(%eax) // q += 20 Is there some reason why GCC couldn't generate this code for the first version of C::f()? Is this a failure of optimization, or am I missing something in how __restricted works? /Ulf