From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30889 invoked by alias); 22 Jan 2014 13:22:45 -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 30851 invoked by uid 48); 22 Jan 2014 13:22:40 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/59594] [4.9 Regression] wrong code (by tree vectorizer) at -O3 on x86_64-linux-gnu Date: Wed, 22 Jan 2014 13:22:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.9.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created 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-01/txt/msg02342.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59594 --- Comment #5 from Jakub Jelinek --- Created attachment 31919 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31919&action=edit gcc49-pr59594.patch Untested patch for discussion. The reason why we (incorrectly) vectorize the testcase is that we ignore the data dependency, on the testcase both the b[a] read vs. b[a+1] store and b[a] store vs. b[a+1] store DDRs have dist 1 and DDR_REVERSED_P set and we ignore those. Now on say: int printf (const char *, ...); int a; static int b[1024]; int main () { for (a = 0; a <= 512; a++) { b[a - 1] = b[a]; b[a] = 1; } printf ("%d\n", b[1]); return 0; } only the b[a] read vs. b[a-1] store is dist 1 DDR_REVERSED_P and b[a] store vs. b[a-1] store is dist 1 !DDR_REVERSED_P, thus we don't vectorize it (correctly). Unfortunately not ignoring dist > 0 && DDR_REVERSED_P ddrs for negative step regresses the testcase I've attached, where there is a write after read ddr and it works properly with the current check. While the attached patch keeps that testcase (no-vfa-vect-depend*.c) working and fixes the test (pr59594.c), the conditions are piled completely randomly, I'm afraid I don't know why it is so, if for the DDR_REVERSED_P continue it matters whether step is positive or negative, or if that is irrelevant and all the write after write DDR_REVERSED_P ddrs need to be checked normally (abs (dist) >= *max_vf), or if say only write after read should be treated as the code treats it right now and even read after write is problematic. The DDR_REVERSED_P stuff has been added in 2007 for PR32377, see e.g. http://gcc.gnu.org/ml/gcc-patches/2007-09/msg01067.html Richard, any ideas?