From patchwork Sat Mar 17 10:21:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 131971 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp497905ljb; Sat, 17 Mar 2018 03:21:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELuLWYIJoDW8mRApRFNVhYM9Q1qAt1vZRFKD7HCgsACRRZKLjY7NU9CZY3upVXIOJwZyqLLY X-Received: by 10.101.77.195 with SMTP id q3mr3958041pgt.283.1521282095830; Sat, 17 Mar 2018 03:21:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521282095; cv=none; d=google.com; s=arc-20160816; b=pXFoEsEJKqdtrUgVXbdVk3v4SoNDpiFektg1myYZptSOMJOkO3BFVleykC3TLnOcVI I0MeSejCLgzt0nGJBnlsZ1o0dTyLEIeIuBgyYw2IRy7bLsyesuQ3T+Mcy3YJFVJt4dJt Nnoo08FpxXgPM20O/0UHb+QRWvkgpZCoEBLV3InHXl0t1RPjS7iJ/bKTYhvFNYze85LH rfQQ6wLzdlnmzaX4DPkLBsRLrAnhzWvVbdNK30a1MpntUkqOa6NChiySxNJSsHZTgteM u4n7htm8Y4q8AOYJ/ljr390Vm3RT+Hsto8vSj4sS2HVVK193BUzGhOKnQtAlDZ/cg9Xm e58A== 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=swqJrxNSrLp8MXgY9XvmKthtkcrAqXRy9gPLrEW3bbE=; b=M3OlQP/QsxrvxWQYteFcwm8K1eTZJWh/EEyf//H9ex8Xup6J7Izerxj1aOssiXyFkC XVL3M0lg8jZyz8uzp1JNZYzTkXl7yqfykynahocFL5xpIM7XO/drHarNeoVtJxaOeBNB WSOHY9OTrbItBfH7gpmcGbvXyJ/PGiljxHVuiqMrlTVCF9DVL2L2ilCaSjIpyJim7blp U5k9oX9oHL6kkUBRe2Er+7gmmutFoOmhtJaewbwTy+G0rd9Zlj2ykIS/faykaELUaEFw 5ic2ykggS5A4UYwj1FINImY/fSGxudxi7Hgof9YbfiaBQ3sSzyz2zhm2e5G84vGRHT92 +vFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=We2SIduw; spf=pass (google.com: domain of gcc-patches-return-474899-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474899-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 bc5-v6si7896178plb.506.2018.03.17.03.21.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 03:21:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-474899-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=We2SIduw; spf=pass (google.com: domain of gcc-patches-return-474899-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474899-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=Uu90xfVAAlPqKoe6M+qBIfvqvw6+8s1Tx6o8r6Orr3aszThyW9dSs mMRFnjaIAS6Q3i4wk5KxiBBLXYLHbzWFhkzGNIto1eKYzh78DXyNTgfk/YMDBV95 a07xmpw2dPRPQI42iEs48nG4/y7GhLnDF43TlyVHNlfHBIs8ln1Nek= 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=jgPEMG2YwJjjMTp61200j/HnHnk=; b=We2SIduwugEmDPNVSfMr PVL4z0FNVTpWCgfZY+/H/7QCtwvjVC0IU/ObqtfPwKzVxizxzb0y10kbdADj7USO VeVjKGXYZnRDrGCIqh3EnjvUFDaK6yo+I2d9miHuEXrhwWgQJZfgj/4ie+VZNmpf FgpfQsk/q4XVrisT5vZOs2o= Received: (qmail 25138 invoked by alias); 17 Mar 2018 10:21:24 -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 25123 invoked by uid 89); 17 Mar 2018 10:21:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2562, x_3 X-HELO: mail-wr0-f171.google.com Received: from mail-wr0-f171.google.com (HELO mail-wr0-f171.google.com) (209.85.128.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Mar 2018 10:21:22 +0000 Received: by mail-wr0-f171.google.com with SMTP id d10so13938725wrf.3 for ; Sat, 17 Mar 2018 03:21:21 -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=swqJrxNSrLp8MXgY9XvmKthtkcrAqXRy9gPLrEW3bbE=; b=NaxxusZZId28Sc+Sc1F8hh8CLH9I6BPx5AtIMezMFJKxV3GlxFxqo5aSxqGpx/h8Ey XYF3Q6GGXf7QY7zXIgKHCWZG42QHPlrvzBZAIUUe7zoQvm3pcgc/es/01Iz8hps3A6Kf 4UkiKr80EvVXnmTnwTsJ/e0pyfEqfbV4Ps1VOszQS4pzki3QjJfjDvvwgs+f3nHhhU8T ijQLqLZkXdTKfm3bRVgz3rOBGaVY+DajA/oU2fEolp6PTBPOutSRSZVxCEj0NXbejrTB MIaCDUOyyk75YMHze2tP0KAsOh7LCxlADe5Bat5JgBbHOetJb1oPJJYtnwqcG/6CJmlg DMvw== X-Gm-Message-State: AElRT7E0z3D8NyliKe+szqP0DdHCWBPj43eI+avB+yQuECgEmprw0Fx0 Oi5RlNEA1FWp4tN/tTpBfTxyPvrh3LM= X-Received: by 10.223.162.201 with SMTP id t9mr4064001wra.148.1521282079803; Sat, 17 Mar 2018 03:21:19 -0700 (PDT) Received: from localhost (79.58.7.51.dyn.plus.net. [51.7.58.79]) by smtp.gmail.com with ESMTPSA id j12sm6884995wmc.18.2018.03.17.03.21.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 17 Mar 2018 03:21:18 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Don't try to vectorise COND_EXPR reduction chains (PR 84913) Date: Sat, 17 Mar 2018 10:21:18 +0000 Message-ID: <87605v0zq9.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 The testcase ICEd for both SVE and AVX512 because we were trying to vectorise a chain of COND_EXPRs as a reduction and getting confused by reduc_index == -1. We normally handle reduction chains by vectorising all statements except the last one normally, but that wouldn't work here for the reasons explained in the comment. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2018-03-17 Richard Sandiford gcc/ PR tree-optimization/84913 * tree-vect-loop.c (vectorizable_reduction): Don't try to vectorize chains of COND_EXPRs. gcc/testsuite/ PR tree-optimization/84913 * gfortran.dg/vect/pr84913.f90: New test. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2018-03-01 08:20:43.850526185 +0000 +++ gcc/tree-vect-loop.c 2018-03-17 10:19:19.289947549 +0000 @@ -6788,6 +6788,30 @@ vectorizable_reduction (gimple *stmt, gi /* If we have a condition reduction, see if we can simplify it further. */ if (v_reduc_type == COND_REDUCTION) { + /* TODO: We can't yet handle reduction chains, since we need to treat + each COND_EXPR in the chain specially, not just the last one. + E.g. for: + + x_1 = PHI + x_2 = a_2 ? ... : x_1; + x_3 = a_3 ? ... : x_2; + + we're interested in the last element in x_3 for which a_2 || a_3 + is true, whereas the current reduction chain handling would + vectorize x_2 as a normal VEC_COND_EXPR and only treat x_3 + as a reduction operation. */ + if (reduc_index == -1) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "conditional reduction chains not supported\n"); + return false; + } + + /* vect_is_simple_reduction ensured that operand 2 is the + loop-carried operand. */ + gcc_assert (reduc_index == 2); + /* Loop peeling modifies initial value of reduction PHI, which makes the reduction stmt to be transformed different to the original stmt analyzed. We need to record reduction code for Index: gcc/testsuite/gfortran.dg/vect/pr84913.f90 =================================================================== --- /dev/null 2018-03-17 08:19:33.716019995 +0000 +++ gcc/testsuite/gfortran.dg/vect/pr84913.f90 2018-03-17 10:19:19.286947657 +0000 @@ -0,0 +1,13 @@ +! { dg-do compile } + +function foo(a, b, c, n) + integer :: a(n), b(n), c(n), n, i, foo + foo = 0 + do i = 1, n + if (a(i) .eq. b(i)) then + foo = 1 + else if (a(i) .eq. c(i)) then + foo = 2 + end if + end do +end function foo