From patchwork Tue Jan 16 13:29:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 124668 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1014256lje; Tue, 16 Jan 2018 05:29:32 -0800 (PST) X-Google-Smtp-Source: ACJfBotCZUDBhtrFmsLjUToIZp/jptZU1umYQqTiw8sPw1pCxe17OAV7lo1svLZ0ZLNKl0hYedzW X-Received: by 10.99.36.68 with SMTP id k65mr24416203pgk.345.1516109372658; Tue, 16 Jan 2018 05:29:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516109372; cv=none; d=google.com; s=arc-20160816; b=Csz1/RMka8vaYA57hC6mFiGVJQOhnzxgTQc+NcnNrr2XUw68UAfEDtdVrgU/0lA/0l WgZsaNbebTR5gHmEEUTrFso24zwfkACBOl9fQGMf5UgQzUZRlNh5H5D4dyGBw+QyoRT1 WtWepw7a4b8yCyhevbToVFPMB8drwB4RjPDmjVa/NalU2dYiP6wRBzvyoxZbkglrJ8Hc mkZ379FvsFy4zKGyvx1YqicOoEU+8IFLecet5bRyoMsIG49QJbJ/qP8mWTb5LO9VSXri wNIixljIOobj/idaEecmWvASC9XKlNb4W8wss17yaTWOl3sBtD0DsyZg3PB6+wiyji9v cLxg== 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=czTwHM8QCJyx4h2ZCmnyEBHwfiRQ3u8M7CqLy5Tc+Cw=; b=YIBu47H5fVipdsQl9Q2HbGyZJy7EjwANoa4K/DVtuAOfqjDpkNzX1vnMqB+ia+93FS yCZxLSu1h0rZXkb0CG0KqYmPb6qmiqyrNaHODDXX2jhHuhhqJ/Blv7nAkHORLa6xQr4o Op4j+NuvO3y841+QN0CCa6k21xjhkYLbDxlmpSO67p1WVmrHT9EJ1zPCKWa1MTvB7a1a Bs7m7Jrov/pVUHmRbSXjkiXkoYvo36qBBm02FayV1Mqu9jDsFvPZ+xwfmB70dROvxFq8 qWOmpMSTjSRUtE/uM7UVsT0kCn4OK9SMn1L1n2GlbUw/8p5dqgo12C7DlDHJCP360tLG i0zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dvhCK51d; spf=pass (google.com: domain of gcc-patches-return-471370-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-471370-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 o10si1639471pgf.764.2018.01.16.05.29.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 05:29:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-471370-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=dvhCK51d; spf=pass (google.com: domain of gcc-patches-return-471370-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-471370-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=sYRvt9fG2YE4oAgZcJ1+W1YqGa5gW520OiZAYmEWCY2ksiD17eiSI Ql+cuOyrALaP/1DjiQqCP/znoWNmSXZ4sDyrjToi1omPXwFfED403ZbRenXfVCob YQ8MuzV9VnRAeV44J70PALmhk9iErEKnft8GrDqD1RMrhWAaVAXQVw= 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=wGji7fxPFQ65+pKm6Fei+c8dqdU=; b=dvhCK51d7EBEIxf31n8H hIwD1NkDONqTkvrDMOzyref4RPJCYRF2OkKLAn+W2srYYq5YSR8VgbCvpl9Qh8+Y WDzBetyJDO+2+cbkXSd40laGVHNCjuj9PQV2LdHKWPNNTQkVyHrru5G2mW7QJ56U 86Z5HDlVg0Aq7wxYrV7x2c4= Received: (qmail 96410 invoked by alias); 16 Jan 2018 13:29:20 -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 96399 invoked by uid 89); 16 Jan 2018 13:29:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.7 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=ok X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jan 2018 13:29:14 +0000 Received: by mail-wm0-f54.google.com with SMTP id f71so8390651wmf.0 for ; Tue, 16 Jan 2018 05:29:13 -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=czTwHM8QCJyx4h2ZCmnyEBHwfiRQ3u8M7CqLy5Tc+Cw=; b=QU3/8qzbKgZqlOZxgnVanNzinBD9J9Lskp+uqrDCQOjQ9N1azn7kCnhrpHPOZHvGL1 Du16V7mNFHJg79CFbt+7gRyj1C1TF4vd4I9bgRWJI4/4RkvA4jt5OaGZ+USQDGSL6509 WksqXA3VQTstyold+KfH4UmBlRKRdFZgrp08EL2DlDDnBcoV3xGbNdUUtOBFeylNc5Sa 7xVPzD2xywvC1hHFk2E5fE4Ojlaa6g2oZEi0zF4/GTG2CFClKszMaOSGrHeuniMHbK30 jYWv8HvlC7oiSug9M+0ddScfDgxh7asopFlKKrCbBJH51F6XmcYQfvbuZD29J78ej1GO 9XHA== X-Gm-Message-State: AKwxyteL0L9tiwk1fvE2pioWQuDDK7GlBwYCQq6cK+SKQxGg9gCqEgFl /u4PggfSh301+Rv3ldsAiAuAISi9kQk= X-Received: by 10.28.7.2 with SMTP id 2mr12791037wmh.9.1516109351546; Tue, 16 Jan 2018 05:29:11 -0800 (PST) Received: from localhost ([95.144.14.233]) by smtp.gmail.com with ESMTPSA id s19sm1436905wrg.29.2018.01.16.05.29.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Jan 2018 05:29:10 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Two fixes for live-out SLP inductions (PR 83857) Date: Tue, 16 Jan 2018 13:29:09 +0000 Message-ID: <874lnmx78a.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 vect_analyze_loop_operations was calling vectorizable_live_operation for all live-out phis, which led to a bogus ncopies calculation in the pure SLP case. I think v_a_l_o should only be passing phis that are vectorised using normal loop vectorisation, since vect_slp_analyze_node_operations handles the SLP side (and knows the correct slp_index and slp_node arguments to pass in, via vect_analyze_stmt). With that fixed we hit an older bug that vectorizable_live_operation didn't handle live-out SLP inductions. Fixed by using gimple_phi_result rather than gimple_get_lhs for phis. Tested on aarch64-linux-gnu. OK to install? Richard 2018-01-16 Richard Sandiford gcc/ PR tree-optimization/83857 * tree-vect-loop.c (vect_analyze_loop_operations): Don't call vectorizable_live_operation for pure SLP statements. (vectorizable_live_operation): Handle PHIs. gcc/testsuite/ PR tree-optimization/83857 * gcc.dg/vect/pr83857.c: New test. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2018-01-13 18:02:00.950360196 +0000 +++ gcc/tree-vect-loop.c 2018-01-16 13:24:33.022528019 +0000 @@ -1851,7 +1851,10 @@ vect_analyze_loop_operations (loop_vec_i ok = vectorizable_reduction (phi, NULL, NULL, NULL, NULL); } - if (ok && STMT_VINFO_LIVE_P (stmt_info)) + /* SLP PHIs are tested by vect_slp_analyze_node_operations. */ + if (ok + && STMT_VINFO_LIVE_P (stmt_info) + && !PURE_SLP_STMT (stmt_info)) ok = vectorizable_live_operation (phi, NULL, NULL, -1, NULL); if (!ok) @@ -8217,7 +8220,11 @@ vectorizable_live_operation (gimple *stm gcc_assert (!LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)); /* Get the correct slp vectorized stmt. */ - vec_lhs = gimple_get_lhs (SLP_TREE_VEC_STMTS (slp_node)[vec_entry]); + gimple *vec_stmt = SLP_TREE_VEC_STMTS (slp_node)[vec_entry]; + if (gphi *phi = dyn_cast (vec_stmt)) + vec_lhs = gimple_phi_result (phi); + else + vec_lhs = gimple_get_lhs (vec_stmt); /* Get entry to use. */ bitstart = bitsize_int (vec_index); Index: gcc/testsuite/gcc.dg/vect/pr83857.c =================================================================== --- /dev/null 2018-01-15 18:48:25.844002736 +0000 +++ gcc/testsuite/gcc.dg/vect/pr83857.c 2018-01-16 13:24:33.021528058 +0000 @@ -0,0 +1,30 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ffast-math" } */ + +#define N 100 + +double __attribute__ ((noinline, noclone)) +f (double *x, double y) +{ + double a = 0; + for (int i = 0; i < N; ++i) + { + a += y; + x[i * 2] += a; + x[i * 2 + 1] += a; + } + return a - y; +} + +double x[N * 2]; + +int +main (void) +{ + if (f (x, 5) != (N - 1) * 5) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump "Loop contains only SLP stmts" "vect" { target vect_double } } } */ +/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" { target vect_double } } } */