From patchwork Tue Jul 19 06:25:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 2751 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5120C23F41 for ; Tue, 19 Jul 2011 06:25:33 +0000 (UTC) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.216.173]) by fiordland.canonical.com (Postfix) with ESMTP id 0CA6EA182C2 for ; Tue, 19 Jul 2011 06:25:32 +0000 (UTC) Received: by qyk10 with SMTP id 10so2328010qyk.11 for ; Mon, 18 Jul 2011 23:25:32 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr6265903qcb.38.1311056732453; Mon, 18 Jul 2011 23:25:32 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs76895qcb; Mon, 18 Jul 2011 23:25:32 -0700 (PDT) Received: by 10.68.42.36 with SMTP id k4mr8246818pbl.16.1311056730919; Mon, 18 Jul 2011 23:25:30 -0700 (PDT) Received: from mail-pz0-f46.google.com (mail-pz0-f46.google.com [209.85.210.46]) by mx.google.com with ESMTPS id o4si13994937pbi.55.2011.07.18.23.25.29 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Jul 2011 23:25:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.210.46 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) client-ip=209.85.210.46; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.46 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) smtp.mail=ira.rosen@linaro.org Received: by pzk3 with SMTP id 3so4590797pzk.5 for ; Mon, 18 Jul 2011 23:25:29 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.233.10 with SMTP id f10mr3317621wfh.53.1311056729229; Mon, 18 Jul 2011 23:25:29 -0700 (PDT) Received: by 10.143.62.16 with HTTP; Mon, 18 Jul 2011 23:25:29 -0700 (PDT) Date: Tue, 19 Jul 2011 09:25:29 +0300 Message-ID: Subject: [patch] Fix PR tree-optimization/49771 From: Ira Rosen To: gcc-patches@gcc.gnu.org Cc: Patch Tracking Hi, The vectorizer performs the following alias checks for data-refs with unknown dependence: ((store_ptr_0 + store_segment_length_0) <= load_ptr_0) || (load_ptr_0 + load_segment_length_0) <= store_ptr_0)) where segment_length is data-ref's step in the loop multiplied by the loop's number of iterations (in the general case). For invariant data-refs segment_length is 0, since the step is 0. This creates incorrect check for: for (i = 0; i < 1000; i++) for (j = 0; j < 1000; j++) a[j] = a[i] + 1; We check: &a + 4000 <= &a + i*4 || &a + i*4 <= &a and the second check is wrong for i=0. This patch makes segment_length to be sizeof (data-ref type) in case of zero step, changing the checks into &a + 4000 <= &a + i*4 || &a + i*4 + 4 <= &a Bootstrapped and tested on powerpc64-suse-linux. Committed revision 176434. Ira ChangeLog: PR tree-optimization/49771 * tree-vect-loop-manip.c (vect_vfa_segment_size): In case of zero step, set segment length to the size of the data-ref's type. testsuite/ChangeLog: PR tree-optimization/49771 * gcc.dg/vect/pr49771.c: New test. Index: tree-vect-loop-manip.c =================================================================== --- tree-vect-loop-manip.c (revision 176433) +++ tree-vect-loop-manip.c (working copy) @@ -2356,9 +2356,14 @@ static tree vect_vfa_segment_size (struct data_reference *dr, tree length_factor) { tree segment_length; - segment_length = size_binop (MULT_EXPR, - fold_convert (sizetype, DR_STEP (dr)), - fold_convert (sizetype, length_factor)); + + if (!compare_tree_int (DR_STEP (dr), 0)) + segment_length = TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr))); + else + segment_length = size_binop (MULT_EXPR, + fold_convert (sizetype, DR_STEP (dr)), + fold_convert (sizetype, length_factor)); + if (vect_supportable_dr_alignment (dr, false) == dr_explicit_realign_optimized) { Index: testsuite/gcc.dg/vect/pr49771.c =================================================================== --- testsuite/gcc.dg/vect/pr49771.c (revision 0) +++ testsuite/gcc.dg/vect/pr49771.c (revision 0) @@ -0,0 +1,26 @@ +#include +#include + +static int a[1000]; + +int +foo (void) +{ + int j; + int i; + for (i = 0; i < 1000; i++) + for (j = 0; j < 1000; j++) + a[j] = a[i] + 1; + return a[0]; +} + +int +main (void) +{ + int res = foo (); + if (res != 1999) + abort (); + return 0; +} + +/* { dg-final { cleanup-tree-dump "vect" } } */