From patchwork Fri Sep 15 10:48:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 112708 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp453573edb; Fri, 15 Sep 2017 03:48:46 -0700 (PDT) X-Received: by 10.99.56.29 with SMTP id f29mr23875410pga.328.1505472526602; Fri, 15 Sep 2017 03:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505472526; cv=none; d=google.com; s=arc-20160816; b=vtDUHWmS1a92359+3+6bBb2IcZSofuVoKBs1UMqe89PCThWWC2Q0I00whBXhK8o3uY 7BXICnxSkEznFYscRveC89ECHkZ93r2xO38TKkcDwvLzo5zIdia19pAuau/Lw3uj/GMq QeFhBVJtC9/yElUD16MD7E9JskkPGDQ4P9Mszk1rx4aQJp4tI+PHoS9Hj4nmW+GdGm31 4qHd8/lm2ZDE9QCxyVQC3ou69+HH3WxOXeLmo1slEJuzR8Gz7dGYfgXECCLK0Sg1Ojbj wG4nf134GW1ebGWQCrH9KkTL9OC21GXyhnDsfVfOvmB3R1PNqXsgbXYgrGctIlJxh6s8 bzmw== 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=pTu+tuG1adBJpQZ3T4A53FPYI+oOpfY7VwsQaUMrxz8=; b=vBOKNHA/02oQx8EnjTf9SIJ+HTY/8l8PZdZyESX9FpAB9JP3t44ni94Devd0plMXlS X1ZEqd8oEG1Xnph7vzlqRilYpxuHQmOLhdMPCB+63OwUAFE/bjTcosd1bzhiEw0OWR6M WCshUxXiZhE/ty1Xjt1mRbWE5LcFo4aJ+xpAnpuz6QD4hcxWL/WOX+E2zAwQKpARVCi9 IMvdXfaINy1DdNIUPrv8DAXp944JgVhxH+h+RWbC8gGKYKFVuhR0K0HPYCI6onLDC0eK 6mDhcns/3mlKeXVrMYLTd2n8hD936DNbdxXsDRuTfRv444n5Sk3q0+RJmwOe93d4j0Fj ha/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=P+k2sH34; spf=pass (google.com: domain of gcc-patches-return-462220-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462220-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 k63si458080pfk.164.2017.09.15.03.48.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:48:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-462220-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=P+k2sH34; spf=pass (google.com: domain of gcc-patches-return-462220-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462220-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=JojIMCl8nffV+4PYeuiEplI7Ej8v2AEGURoUuDqAViFQ9H9U7S/xi 8tJubGB9+OkHC8KKa63ilsJLV4c4Sv7/QzuhgMv3XVeZHqsoNhV7X22A5J2UjsXm 2eMEI99CSb1Ir/i+vSpGCU7ejRM5NNVrA0A5rGfTqUIOtFJg5Zz15I= 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=1SCuyEhjIWBRqEtfQacxvxx0B7A=; b=P+k2sH34RFK+rCqeqxPa q8nHmS2XK5gHdu60AGb4kj3YU6FA2aXjF32MofJePSL6Ya6G7cRCcSvWeMKcmCdy KlwlTbyqcBxmHfUpAx0I9iQ64BAUidR5aJjjCYWV7ViFEQeAys9+S9OVIbdflq1V zt74iUjqaJ29TLiQ3jFfcLQ= Received: (qmail 84548 invoked by alias); 15 Sep 2017 10:48: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 84397 invoked by uid 89); 15 Sep 2017 10:48:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, 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; Fri, 15 Sep 2017 10:48:13 +0000 Received: by mail-wr0-f180.google.com with SMTP id w12so1487674wrc.7 for ; Fri, 15 Sep 2017 03:48:07 -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=pTu+tuG1adBJpQZ3T4A53FPYI+oOpfY7VwsQaUMrxz8=; b=jUQrobB/jWTUmBvkqN/5zs+FYfkik7kGasoGTqhpw6ahp+w+C1VmpFh4Iq+N55UZJy NWVxpMaPURXoa8FikVO+KQ7PLID6fymqIdApG7WYEO6JpW+9Y0r32v1LzlzUHOTYjC1U iUrgW0gpTaJkr8ucDlAK0cODmjsCDqbOWWFw+TZHsA6oiJ4lK2XvCNQfldC/koUZmo/0 7lLbz7AXxS4851b9nS/pAU2Zff9FatzLi16Cp6R9WNj9t3DzqIoqmuEp9kd1cBgFqPmH B7UPeHcqsku0EZKgFu2n9L8a6s/GS3RsHHdBG/hjRmhE9HTrpEWnhpRMpKNUIDqSqrIE e6bA== X-Gm-Message-State: AHPjjUiA540X9D+UViSCF4AvF2696+55Tj5PBPaL7JQ3Jpg1Kg3gpsND rpIThj6W/cmocupoHVLJpA== X-Google-Smtp-Source: ADKCNb66hUMwslWrAjbH0/Seq/IPLFAqS5+ByS35sXtV+sjF6GnMhvL9+FKZF+hvqrw75v8kEJUE8Q== X-Received: by 10.223.184.181 with SMTP id i50mr19692011wrf.136.1505472485738; Fri, 15 Sep 2017 03:48:05 -0700 (PDT) Received: from localhost (92.40.248.1.threembb.co.uk. [92.40.248.1]) by smtp.gmail.com with ESMTPSA id s196sm938650wmb.6.2017.09.15.03.48.04 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Sep 2017 03:48:05 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Include phis in SLP unrolling calculation Date: Fri, 15 Sep 2017 11:48:03 +0100 Message-ID: <871sn8nspo.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Without this we'd pick an unrolling factor based purely on longs, ignoring the ints. It's posssible that vect_get_smallest_scalar_type should also handle shifts, but I think we'd still want this as a belt-and-braces fix. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. OK to install? Richard 2017-09-15 Richard Sandiford gcc/ * tree-vect-slp.c (vect_record_max_nunits): New function, split out from... (vect_build_slp_tree_1): ...here. (vect_build_slp_tree_2): Call it for phis too. gcc/testsuite/ * gcc.dg/vect/slp-multitypes-13.c: New test. Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c 2017-09-15 11:35:46.833592065 +0100 +++ gcc/tree-vect-slp.c 2017-09-15 11:40:10.286573578 +0100 @@ -480,6 +480,48 @@ vect_get_and_check_slp_defs (vec_info *v return 0; } +/* A subroutine of vect_build_slp_tree for checking VECTYPE, which is the + caller's attempt to find the vector type in STMT with the narrowest + element type. Return true if VECTYPE is nonnull and if it is valid + for VINFO. When returning true, update MAX_NUNITS to reflect the + number of units in VECTYPE. VINFO, GORUP_SIZE and MAX_NUNITS are + as for vect_build_slp_tree. */ + +static bool +vect_record_max_nunits (vec_info *vinfo, gimple *stmt, unsigned int group_size, + tree vectype, unsigned int *max_nunits) +{ + if (!vectype) + { + if (dump_enabled_p ()) + { + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "Build SLP failed: unsupported data-type in "); + dump_gimple_stmt (MSG_MISSED_OPTIMIZATION, TDF_SLIM, stmt, 0); + dump_printf (MSG_MISSED_OPTIMIZATION, "\n"); + } + /* Fatal mismatch. */ + return false; + } + + /* If populating the vector type requires unrolling then fail + before adjusting *max_nunits for basic-block vectorization. */ + if (is_a (vinfo) + && TYPE_VECTOR_SUBPARTS (vectype) > group_size) + { + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "Build SLP failed: unrolling required " + "in basic block SLP\n"); + /* Fatal mismatch. */ + return false; + } + + /* In case of multiple types we need to detect the smallest type. */ + if (*max_nunits < TYPE_VECTOR_SUBPARTS (vectype)) + *max_nunits = TYPE_VECTOR_SUBPARTS (vectype); + + return true; +} /* Verify if the scalar stmts STMTS are isomorphic, require data permutation or are of unsupported types of operation. Return @@ -560,38 +602,14 @@ vect_build_slp_tree_1 (vec_info *vinfo, scalar_type = vect_get_smallest_scalar_type (stmt, &dummy, &dummy); vectype = get_vectype_for_scalar_type (scalar_type); - if (!vectype) - { - if (dump_enabled_p ()) - { - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "Build SLP failed: unsupported data-type "); - dump_generic_expr (MSG_MISSED_OPTIMIZATION, TDF_SLIM, - scalar_type); - dump_printf (MSG_MISSED_OPTIMIZATION, "\n"); - } + if (!vect_record_max_nunits (vinfo, stmt, group_size, vectype, + max_nunits)) + { /* Fatal mismatch. */ matches[0] = false; return false; } - /* If populating the vector type requires unrolling then fail - before adjusting *max_nunits for basic-block vectorization. */ - if (is_a (vinfo) - && TYPE_VECTOR_SUBPARTS (vectype) > group_size) - { - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "Build SLP failed: unrolling required " - "in basic block SLP\n"); - /* Fatal mismatch. */ - matches[0] = false; - return false; - } - - /* In case of multiple types we need to detect the smallest type. */ - if (*max_nunits < TYPE_VECTOR_SUBPARTS (vectype)) - *max_nunits = TYPE_VECTOR_SUBPARTS (vectype); - if (gcall *call_stmt = dyn_cast (stmt)) { rhs_code = CALL_EXPR; @@ -1018,6 +1036,12 @@ vect_build_slp_tree_2 (vec_info *vinfo, the recursion. */ if (gimple_code (stmt) == GIMPLE_PHI) { + tree scalar_type = TREE_TYPE (PHI_RESULT (stmt)); + tree vectype = get_vectype_for_scalar_type (scalar_type); + if (!vect_record_max_nunits (vinfo, stmt, group_size, vectype, + max_nunits)) + return NULL; + vect_def_type def_type = STMT_VINFO_DEF_TYPE (vinfo_for_stmt (stmt)); /* Induction from different IVs is not supported. */ if (def_type == vect_induction_def) Index: gcc/testsuite/gcc.dg/vect/slp-multitypes-13.c =================================================================== --- /dev/null 2017-09-15 10:12:35.472207962 +0100 +++ gcc/testsuite/gcc.dg/vect/slp-multitypes-13.c 2017-09-15 11:40:10.285573591 +0100 @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +void +f (long *x, int n) +{ + for (int i = 0; i < n; i++) + { + x[i * 2] = 1L << i; + x[i * 2 + 1] = 1L << i; + } +}