From patchwork Wed Feb 28 14:20:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 129995 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1079784lja; Wed, 28 Feb 2018 06:20:44 -0800 (PST) X-Google-Smtp-Source: AH8x227Ka0Q2TrEOgUJKDAa5B5OAC2CIQetOYsFe7esllqLQD9Jvcc9R2XSzQ7HGmpWWr+9dQR6f X-Received: by 2002:a17:902:96a:: with SMTP id 97-v6mr18242598plm.183.1519827644859; Wed, 28 Feb 2018 06:20:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519827644; cv=none; d=google.com; s=arc-20160816; b=nXQMH/rr6CvmyiMp2Ic3Dh8hAyUD+BPJ5tZjs6Kg0Q7D770Hqq3AZKFfxPEcekn3AO X2SaQ6p1kxXnBbMcJd2vrhQfDAiBtEd8ZBloDnlh9VX0SX4mW24QQt69WjAEPMi57uEY 2sT6HJkTiwn0ORuPB2qLVVLadztpXMX5iuOJvEvbcpsSP3UPCNsEtiD7U2tEM+DipKS3 w1s5zPqFE0q01S9YtfBnPP9rZPlbWUEUG1kesuUUaldGr/Vi6G9yJVrAlAQoUFXG+6KT HbCv2BULeLaNR1DlXes3TOWJNRx3p2GHMHKcYZqyt2C1bZr2SuZkSTyItaJfCibjxVy4 tUag== 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=hktZ5PgbwBajCUi6SMLCFdlWrSEe+GpVr8Mrih20nUk=; b=SqEZh8DqDUwFDJs21PMpPh2eSPW5Weaovj7tC/2oPGnlLYovVZd+GREaO+HlhggzWn YVINQGzAVmBQNMIXHd0RR9sRGwpLb5xA0s4ANFjGHRP6qgI48gcv3X4SHTcGeH5Eoxbu SfbBiJOp6a5ALtGHzjlKka3kY3u0hbQfuouOFK0CAjtWUru8GE4yXvh9eAdpoYF4DeDf VhAvUyUiQ/IesvCU9VOBq2Lohv5H7gN9pr4Eqd/av/qVR+R25zEJY3uhawlvf9SLNvWx 9jmxAg4yRPC+QuhdsDGf6c5jiUiSJ4/qCAZyPN5Jg/yebjGHTakliXAqCLKPFMa6Bs+o 7ckw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i6eIjFp0; spf=pass (google.com: domain of gcc-patches-return-474015-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474015-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 r1-v6si1374338plb.102.2018.02.28.06.20.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 06:20:44 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-474015-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=i6eIjFp0; spf=pass (google.com: domain of gcc-patches-return-474015-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474015-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=acOxSpIG7bhlP5mTBXoCsUqVQURHKEGXSM76e1J4+TQX6TSUk1SHg AE6qHmdsQHcpOduIvRrA662MElrlpiZ+cUlJEXhiZneOFtpmP5WpDV3oPIV1of+Z hBsJqDZOufjvQ+yGYBamaX/uL3NVnjaWE3k/2DWF3/i5WHcnilHEVQ= 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=s7Z2OBGt4SZPcY6FSc8RZUr3ze8=; b=i6eIjFp0oe7WzQ23R7yU I+84YrIq26i2IGnXjACRAuCb6fQR5J8ZZ68UCnjAv9xcInO5nor11FKamSKqScv/ LH6QW4Kmk5MCXpnAyVX3xiaQ8m6FXIZ+/K80jBhDNbikX2mixX8y4HMwwW9ONbZ8 Krn1Z4Ay5uZQ78+CrDMix0U= Received: (qmail 119950 invoked by alias); 28 Feb 2018 14:20:33 -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 119941 invoked by uid 89); 28 Feb 2018 14:20:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 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= X-HELO: mail-wr0-f180.google.com Received: from mail-wr0-f180.google.com (HELO mail-wr0-f180.google.com) (209.85.128.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Feb 2018 14:20:32 +0000 Received: by mail-wr0-f180.google.com with SMTP id f14so2586570wre.8 for ; Wed, 28 Feb 2018 06:20:31 -0800 (PST) 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=hktZ5PgbwBajCUi6SMLCFdlWrSEe+GpVr8Mrih20nUk=; b=sIWhgjuLCLpd+9h4x72LzvMe3JhYHk4fIzAb7yCyjDQ6TcVZstG3UCNBGA83y6dZDC 1xE4vRFudBkdG0ckUgR3irHOyuY9nlTQDbLZz7hJJa60qfsW06QF0UrJScHfZ2Yk5xLI CS6ZK6hfx1hmRCJYkAz2WguXoRS65hqMBZnW0k7WI5bNuYxfx0QUGlwEhOICLqxsVNDf tSyQ5Wv2S6uz2x113KbS0NpIjcVrmwnAU3khNkgK6u+wRBcqBzrLdGzz8EtJMl9H5I/W 5AjaBsiok42n+FSDUjWPWD1wYi/KZVtkvbaAyVgWvj5aZz01XVIe+4NK2xOawnIHUDHK hoTw== X-Gm-Message-State: APf1xPBL4h8AIlLcxJ0jscbZi0QlroGuzXNL08seghvyePJh1fMHrjet PnCKs0SkjPapKidR1b92A/O2zTu+Dak= X-Received: by 10.223.176.86 with SMTP id g22mr15399134wra.11.1519827629697; Wed, 28 Feb 2018 06:20:29 -0800 (PST) Received: from localhost ([217.140.96.141]) by smtp.gmail.com with ESMTPSA id u48sm1447354wrb.85.2018.02.28.06.20.28 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2018 06:20:28 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Don't vectorise zero-step rmw operations (PR 84485) Date: Wed, 28 Feb 2018 14:20:27 +0000 Message-ID: <87muzt8ac4.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 GCC 6 and 7 would vectorise: void f (unsigned long incx, unsigned long incy, float *restrict dx, float *restrict dy) { unsigned long ix = 0, iy = 0; for (unsigned long i = 0; i < 512; ++i) { dy[iy] += dx[ix]; ix += incx; iy += incy; } } without first proving that incy is nonzero. This is a regression from GCC 5. It was fixed on trunk in r223486, which versioned the loop based on whether incy is zero, but that's obviously too invasive to backport. This patch instead bails out for non-constant steps in the place that trunk would try a check for zeroness. I did wonder about trying to use range information to prove nonzeroness for SSA_NAMEs, but that would be entirely new code and didn't seem suitable for a release branch. Tested on aarch64-linux-gnu. OK for GCC 7 and 6? I'll add the testcase to trunk too. Richard 2018-02-28 Richard Sandiford gcc/ PR tree-optimization/84485 * tree-vect-data-refs.c (vect_analyze_data_ref_dependence): Return true for zero dependence distances if either step is variable, and if there is no metadata that guarantees correctness. gcc/testsuite/ PR tree-optimization/84485 * gcc.dg/vect/pr84485.c: New test. Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2017-07-27 18:08:43.779978373 +0100 +++ gcc/tree-vect-data-refs.c 2018-02-28 14:16:36.621113244 +0000 @@ -394,6 +394,16 @@ vect_analyze_data_ref_dependence (struct } } + if (!loop->force_vectorize + && (TREE_CODE (DR_STEP (dra)) != INTEGER_CST + || TREE_CODE (DR_STEP (drb)) != INTEGER_CST)) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "step could be zero.\n"); + return true; + } + continue; } Index: gcc/testsuite/gcc.dg/vect/pr84485.c =================================================================== --- /dev/null 2018-02-26 10:26:41.624847060 +0000 +++ gcc/testsuite/gcc.dg/vect/pr84485.c 2018-02-28 14:16:36.620112862 +0000 @@ -0,0 +1,34 @@ +/* { dg-do run } */ + +#include "tree-vect.h" + +#define N 256 + +void __attribute__ ((noinline, noclone)) +f (unsigned long incx, unsigned long incy, + float *restrict dx, float *restrict dy) +{ + unsigned long ix = 0, iy = 0; + for (unsigned long i = 0; i < N; ++i) + { + dy[iy] += dx[ix]; + ix += incx; + iy += incy; + } +} + +float a = 0.0; +float b[N]; + +int +main (void) +{ + check_vect (); + + for (int i = 0; i < N; ++i) + b[i] = i; + f (1, 0, b, &a); + if (a != N * (N - 1) / 2) + __builtin_abort (); + return 0; +}