From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21179 invoked by alias); 6 Feb 2014 08:28:04 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 20563 invoked by uid 48); 6 Feb 2014 08:28:01 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/60086] suboptimal asm generated for a loop (store/load false aliasing) Date: Thu, 06 Feb 2014 08:28:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 4.7.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc everconfirmed Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-02/txt/msg00544.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60086 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2014-02-06 CC| |abel at gcc dot gnu.org, | |jakub at gcc dot gnu.org, | |uros at gcc dot gnu.org, | |vmakarov at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Jakub Jelinek --- GCC right now only handles __restrict on function parameters, so in this case the aliasing info isn't known. While the loop is versioned for aliasing at runtime, the info about that is only known during the vectorizer, therefore e.g. scheduler can hardly know it. The pointers to overaligned memory is something you should generally avoid, __builtin_assume_aligned is what can be used to tell the compiler about the alignment instead, overaligned types often actually hurt generated code instead of improving it. And the way you are calling posix_memalign is IMHO a strict aliasing violation. Perhaps GCC could handle posix_memalign specially as builtin if declared with the right prototype (and optionally some new attribute) and derive both the aliasing and alignment info from it, like the taking of the address of the pointer in it isn't really an escape site of any kind, all the call does is return two values instead of just one, so it could be folded into passing an address of some temporary to the call instead and then loading from the temporary and using some special pass-thru builtin that would tell GCC that the pointer is really malloc-like (non-aliasing anything else) and also use__builtin_assume_aligned. The GNU memalign is far better than posix_memalign from this POV. Anyway, if I rewrite your testcase as: #include #include __attribute__((noinline)) void foo (double *__restrict__ a, double *__restrict__ b, double *__restrict__ c, double *__restrict__ d, unsigned long NSIZE) { unsigned long i, j; a = __builtin_assume_aligned (a, 32); b = __builtin_assume_aligned (b, 32); c = __builtin_assume_aligned (c, 32); d = __builtin_assume_aligned (d, 32); // initialize memory for(i=0; i