From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@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-Google-Smtp-Source: AG47ELtS2X2GCZZw6paegMrH6TlyQAVD/GSScsB16ydzVb5/Lj09nmHliS+zxSs89AdxCrqj7/NJ1A== 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:46:00 -0000 Message-ID: <87605v0zq9.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2018-03/txt/msg00835.txt.bz2 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