From patchwork Thu Aug 9 14:40:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 955684 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-483458-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZfY3FiiE"; 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 41mWCB1sNjz9s1x for ; Fri, 10 Aug 2018 00:40:54 +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=MfP5Jrgdpj59bLx/t1WwRkOggbnYQp3FZ1DmpqJ9JAh/1u5IFQiKf lhyqk1znJnLr5x2RMmB4NvDPl+hGvckxjNgw5vTq9qQgCyX9cZ3PWA9gQMSjzEFz cpxXW+KxS/JPPQdR9ryokx+qaTRIrqpnHIAtrtNPG2tF24RIAoTPV0= 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=tpjqZ84D0qH9+T7C0vCaadEskWc=; b=ZfY3FiiEI/1PT8f9HTFu 8OvXzbOnIEVw3cRU4fflYkpqTP4LUvI5UTSllzWac2LsrKpoTNAl8t2AkK9VWHf1 wC1i5ITqMmN4KaMYk/UJe1vaYIR+wGsF5aOSTHCeGYdLum3mzscSVb3VU2SFYHOA Nj3PU2nAXIsuKJnMNE40CPA= Received: (qmail 21373 invoked by alias); 9 Aug 2018 14:40:46 -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 21355 invoked by uid 89); 9 Aug 2018 14:40:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: foss.arm.com Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Aug 2018 14:40:44 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B5837A9 for ; Thu, 9 Aug 2018 07:40:43 -0700 (PDT) Received: from localhost (unknown [10.32.98.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 12DF03F5B3 for ; Thu, 9 Aug 2018 07:40:42 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Allow inner-loop reductions with variable-length vectors Date: Thu, 09 Aug 2018 15:40:41 +0100 Message-ID: <87tvo31u3a.fsf@arm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 While working on PR 86871, I noticed we were being overly restrictive when handling variable-length vectors. For: for (i : ...) { res = ...; for (j : ...) res op= ...; a[i] = res; } we don't need a reduction operation (although we do for double reductions like: res = ...; for (i : ...) for (j : ...) res op= ...; a[i] = res; which must still be rejected). Tested on aarch64-linux-gnu (with and without SVE), aarch64_be-elf and x86_64-linux-gnu. OK to install? Richard 2018-08-09 Richard Sandiford gcc/ * tree-vect-loop.c (vectorizable_reduction): Allow inner-loop reductions for variable-length vectors. gcc/testsuite/ * gcc.target/aarch64/sve/reduc_8.c: New test. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2018-08-01 16:14:50.227052736 +0100 +++ gcc/tree-vect-loop.c 2018-08-09 15:38:35.230258362 +0100 @@ -6711,6 +6711,7 @@ vectorizable_reduction (stmt_vec_info st } if (reduction_type != EXTRACT_LAST_REDUCTION + && (!nested_cycle || double_reduc) && reduc_fn == IFN_LAST && !nunits_out.is_constant ()) { Index: gcc/testsuite/gcc.target/aarch64/sve/reduc_8.c =================================================================== --- /dev/null 2018-07-26 10:26:13.137955424 +0100 +++ gcc/testsuite/gcc.target/aarch64/sve/reduc_8.c 2018-08-09 15:38:35.230258362 +0100 @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize" } */ + +int +reduc (int *restrict a, int *restrict b, int *restrict c) +{ + for (int i = 0; i < 100; ++i) + { + int res = 0; + for (int j = 0; j < 100; ++j) + if (b[i + j] != 0) + res = c[i + j]; + a[i] = res; + } +} + +/* { dg-final { scan-assembler-times {\tcmpne\tp[0-9]+\.s, } 1 } } */ +/* We ought to use the CMPNE result for the SEL too. */ +/* { dg-final { scan-assembler-not {\tcmpeq\tp[0-9]+\.s, } { xfail *-*-* } } } */ +/* { dg-final { scan-assembler-times {\tsel\tz[0-9]+\.s, } 1 } } */