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: 134789 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5261513lji; Tue, 1 May 2018 11:35:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrbftSVky8mbLJG1SM2WDXSARuGWSinuHivhE23/WpRQ3vbKxEMlhQfAL8+eiWqR2+DfYKN X-Received: by 2002:a63:7b5d:: with SMTP id k29-v6mr13788425pgn.249.1525199700498; Tue, 01 May 2018 11:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525199700; cv=none; d=google.com; s=arc-20160816; b=SS5ScdNXoOB7e6G0UZ4D2UDxVXdPKDvYsr05XyA741ErcQTXXkiONn8j1G2+1jZpQz ke02XF9Uqr0yetgGJSsRX+zM0ONQUGyMmYTgZLn7lmR1b2v5LY5Fv5AG6KMsmH6EvQgX Wv8tU/SUfLEjBhbWdzW4vR38h1O4e8bgAxMfNxf2BzBVJIuKeWxIa6Kvg5qhYxJCcgkC 0GQeAOtnTkbRupuTBv/ltb4fLPhILCnzzdnbIUuQNvLE1P+XxjBCfVIGM8eizsUZtA+j EAHI6aWPnN++yuWUZkyE9Mb6rPmBujkA80IBNXF/CMtJufmJechNt7pEPLzi/vwW9di2 CayQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=S9he9+gf+JKuXftHic7+njZ4tJy+9zRe4NXhDR/WIuU=; b=EOSnqzd8r8XwWh9+FBxGZWZJ+HCDUh6wzxxSlaRqCzqY7NMLOumMBPSJR+wrI6lH1Q U5UGe4A9RVhrl8hdwzpoEUecmIrYcRP92dpLPicbotGhmUvyu5CpxQvnbCOawCH6BGRq TrP6lognbouubmRM94mq+QaMBTuaKQUOTkTYgTRjKiAteti6qrYAPvreXp5BP5Jjvwb8 U5a8TMz1R0LnFD3nDmfqaBvXQLGVX2/RKoLCtbJRQic5ivfMfm5Z9+nT/Hr3DyQtJhFf tvH7X1Uft1k3NcyOG3uuMbWUXyee0tqsPQauLocjcPxWedRkVqQStfzSJH5gT8gdUsma BJuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CMAm1rTt; spf=pass (google.com: domain of gcc-patches-return-477063-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-477063-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j61-v6si9913246plb.317.2018.05.01.11.35.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 11:35:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-477063-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CMAm1rTt; spf=pass (google.com: domain of gcc-patches-return-477063-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-477063-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=INtUuptrUSBd4nNI5/L99uWbhaWHtQUlmAieajacTnrpcwc/U7Dve EJhPJ+2nRpDYSMS8OyIztYFn7JCXJ6NCHX05axxDZsl0mYW2GCXj5NgEd0R3sUjN 5QICkembDkVNabpMFweETM/A59vwD2Araf6XdkK9LK0MVhxkC6mc00= 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=CMAm1rTttH2UTzSEtvRL 0EKOdy3iu7VSLwmyzP64cbTLM9PuzsXLiADuYFFe12Vz0NAUfRSF0Kjx8HGj5A0t mBYTdtqbfBZkyFetOK5JOMYUR5Na7nC4TIdm1FUL2kT+8UEi1vPFzd43/4wUNOFa aGT1zitu3pUzAMp+66mjEZw= 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-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 } } } */