From patchwork Tue May 1 18:34:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 907163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477063-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mT8E04Vn"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40b97N58Mjz9s1d for ; Wed, 2 May 2018 04:34:56 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=mgRJO8t7q6AfTo6Ssz0XhEB/tcmT1H5gajUo2iSTHfi0qYpeFMuRE a2qn2Hmk7Ph5a8NORMH/Enr0K04iriHcVmf9zYKTWA9SLwSCcaEDqqVVQu4K0v9R UVVNyQspwQvRONwJnrF55IFJj8Fhq4nP5IG3ZCJ5RP1qJDeG9aNjE8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=ajo5C+4h8L3fDSiBUGtN7RMbXEU=; b=mT8E04Vn1uoV+4Ej0aLS VRHUq4vvIfnIQiV98+Nxv2JIQEj1sQgQfzAXPb83LJRDVkwciZRkWrq1crWWYcLz GKdsyxOUoY4vaVBXCHoWvHZEBtaKhrVwxjzK5LCtZKg2X/keP51EY5yBFSVR4MoH /CrT7eq7klID5WV4Fc64YuA= Received: (qmail 2464 invoked by alias); 1 May 2018 18:34:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2451 invoked by uid 89); 1 May 2018 18:34:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=VECTORIZED, Hx-languages-length:2444 X-HELO: mail-wm0-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 May 2018 18:34:47 +0000 Received: by mail-wm0-f50.google.com with SMTP id a67so11349053wmf.3 for ; Tue, 01 May 2018 11:34:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=S9he9+gf+JKuXftHic7+njZ4tJy+9zRe4NXhDR/WIuU=; b=m3tiXfRmsgv3XqqRUwRWsL2ikaZmQerAbOE4y9qEgnWAr5PVpIp8oaPlKcLwWI2o8i DPcQ3T/jN0LPCZUJ3LjCiDwtbDcqnXLo4GUTBDreSA8FJVivmn/tghQKA3Ln8LQpoyT+ HmIW6hdnKAvJup3//O6q/yB2w9QPmTehMhP7B151ZHzja4WvE3JLhIIlhFzel3dIhWgm eeXRJhikLLmN6gTjiWB1xmF9uPazEki8srYhyujEYn8afX/wm5hZ4NeYpcoDFK557kF6 njTe9l2hxkyTjxKflfglERug0Dnc8mTT2fiulTAAgUpcl6Kao0rO1IxPevM8dyQ5Azrk de6g== X-Gm-Message-State: ALQs6tCQu2AVhCyzy4KIeap0qTjVnE8LkKFBnDmmzDJzS2kjVQ5ceqGE 4/Gj5G/ibCWXyAVc88+5D9AA96iuEBk= X-Google-Smtp-Source: AB8JxZrucRT4L7gMQZ5ZMvIBY2lpzCSTbPU8EJ+K4XTHKgwC1UqKvRDx6O010GLEmbU6Kev/bjYfBg== X-Received: by 10.28.238.149 with SMTP id j21mr10510231wmi.16.1525199684965; Tue, 01 May 2018 11:34:44 -0700 (PDT) Received: from localhost (116.58.7.51.dyn.plus.net. [51.7.58.116]) by smtp.gmail.com with ESMTPSA id a10-v6sm13063995wri.10.2018.05.01.11.34.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 May 2018 11:34:44 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Tighten early exit in vect_analyze_data_ref_dependence (PR85586) Date: Tue, 01 May 2018 19:34:43 +0100 Message-ID: <87efivtebg.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 The problem in this PR was that we didn't consider aliases between writes in the same strided group. After tightening the early exit we get the expected abs(step) >= 2 versioning check. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK for trunk and GCC 8? Thanks, Richard 2018-05-01 Richard Sandiford gcc/ PR tree-optimization/85586 * tree-vect-data-refs.c (vect_analyze_data_ref_dependence): Only exit early for statements in the same group if the accesses are not strided. gcc/testsuite/ PR tree-optimization/85586 * gcc.dg/vect/pr85586.c: New test. Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2018-05-01 19:30:22.344979421 +0100 +++ gcc/tree-vect-data-refs.c 2018-05-01 19:32:10.404466158 +0100 @@ -305,9 +305,11 @@ vect_analyze_data_ref_dependence (struct return false; /* We do not have to consider dependences between accesses that belong - to the same group. */ + to the same group, unless the stride could be smaller than the + group size. */ if (GROUP_FIRST_ELEMENT (stmtinfo_a) - && GROUP_FIRST_ELEMENT (stmtinfo_a) == GROUP_FIRST_ELEMENT (stmtinfo_b)) + && GROUP_FIRST_ELEMENT (stmtinfo_a) == GROUP_FIRST_ELEMENT (stmtinfo_b) + && !STMT_VINFO_STRIDED_P (stmtinfo_a)) return false; /* Even if we have an anti-dependence then, as the vectorized loop covers at Index: gcc/testsuite/gcc.dg/vect/pr85586.c =================================================================== --- /dev/null 2018-04-20 16:19:46.369131350 +0100 +++ gcc/testsuite/gcc.dg/vect/pr85586.c 2018-05-01 19:32:10.403466206 +0100 @@ -0,0 +1,43 @@ +#define N 100 + +void __attribute__ ((noipa)) +foo (int *out, int *in, int step) +{ + for (int i = 0; i < N; ++i) + { + out[0] = in[i]; + out[1] = 2; + out += step; + } +} + +int in[N]; +int out[N * 2]; + +int +main (void) +{ + for (int i = 0; i < N; ++i) + { + in[i] = i * (i + 1); + asm volatile ("" ::: "memory"); + } + + foo (out, in, 1); + for (int i = 0; i < N; ++i) + if (out[i] != in[i]) + __builtin_abort (); + if (out[N] != 2) + __builtin_abort (); + + foo (out + N - 1, in, -1); + if (out[0] != in[N - 1]) + __builtin_abort (); + for (int i = 1; i <= N; ++i) + if (out[i] != 2) + __builtin_abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "LOOP VECTORIZED" 1 "vect" { target vect_int } } } */