From patchwork Thu Sep 14 11:22:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 112542 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp624820qgf; Thu, 14 Sep 2017 04:23:03 -0700 (PDT) X-Received: by 10.99.160.100 with SMTP id u36mr20949860pgn.22.1505388183161; Thu, 14 Sep 2017 04:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505388183; cv=none; d=google.com; s=arc-20160816; b=n3KW150f4nXtjIkBGSR04lwxv32W/Its52LyDYvX6LVNSXaHKY9QpdXExFY4TYyM/c kKV0dHJC5SaUgIOkrsL3yV9RfcxDBM3vC+EcGG/kDpZD8PBqcvW68Md8ePwXL6sLuk2p 5JJbGiCFVGuYY0JXXGEX2dSHPHhlmeRp7X+LRtqJxGLEiReOOte/6thDiPxeCexDrJZi SG/PABvBvjSegdCpDQ1w7IXSow+nBf4zl/b85av0eal9T2QMVJmos73diGogJfIe3U3V 9XqRE+QEeJU38ZH14xuH8+iC5AtZRR4Gf82SdBc67ojIM5O7daENsuk7e13oS6JRzShe Iscg== 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=cTPNPNTChbHMVcobXOXswQvq7MmVjNHRpoNaS+SMA3o=; b=e3NVpR6DYL7HF9s9LbeCVrvhQAemr6BbmpGseAFieoFJeL4piIt/xhyA4eEdtfiRy2 fdcdPh+BaoePAguiZn4CwoooaeRaNxWv07zjyVlF2Z8NXmm3IY1U57ZfLbz3EVAl+M6T nkoK6/YiC6EUuuY7R0MK575IyIXfClqcHAPZcQTcat4Y5LdivgZ7NaouUJ9zChNEEDKu xVTnUB2DKAOS8D9wWggrnUG9J62ZEaz6Ba5MTMZM/PCPrMKzX2+wPkxaOQMM0/OTP1T2 NLgHz7nMc3a6YdXAwPjorHco2ZaKOxPNMmVbsHC4EQnOBpkfEK0k2rpI1+wl+0O6BAZV Yx8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=INa3OfVz; spf=pass (google.com: domain of gcc-patches-return-462122-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462122-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 o1si4453144pld.538.2017.09.14.04.23.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Sep 2017 04:23:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-462122-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=INa3OfVz; spf=pass (google.com: domain of gcc-patches-return-462122-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462122-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=U0z+ahmCiQGlQqahENr3tQckBoNwlIAhf/PwqgYIfx2CvWeMrQ8Oq KXrgBMNSjVoHDzQXAoIax+0X6NAsvprY95uIj8qTha218h1hn/ulKQ6kQ9xZgaoR +bEoXZfXqqe+nlboNbZ6CVbL7B7TJilZuNmoYH5M29/mLspQP4kS/A= 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=ap1rmMyrZEu90LNYBxn0KDPdCcY=; b=INa3OfVzedk8i16A1rVf +Qufs7XpHV7v+zLuMJGxIGqwxvgGtxUsLHPSwFmp1x1VUjBd1QEjRYBwHaZqAXW8 S5fh46jG11pHeXTc6cIvwnZ6ZEvDHWggFbQS/V+PFAjSDVN5maDnfu3Ht6ijZT4K ACa6bZD4srvMrHmc6ROR914= Received: (qmail 36214 invoked by alias); 14 Sep 2017 11:22:51 -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 34849 invoked by uid 89); 14 Sep 2017 11:22:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=decomposing, HX-Received:10.223.198.202 X-HELO: mail-wr0-f172.google.com Received: from mail-wr0-f172.google.com (HELO mail-wr0-f172.google.com) (209.85.128.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Sep 2017 11:22:48 +0000 Received: by mail-wr0-f172.google.com with SMTP id l22so34617wrc.10 for ; Thu, 14 Sep 2017 04:22:48 -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=cTPNPNTChbHMVcobXOXswQvq7MmVjNHRpoNaS+SMA3o=; b=TiKE3RPuANt4Gq8lO92sNQ0gr804t1Ky0MlGPmTN12fK6hZ8hej3OIrMLZrNp7pwAL y2oo5i/soI+HfEZqT81QcRqWQo4kigo1xEmuwyoYuD5pb5PgTHd5ZibR3JvKnncdPldN tL+npE1kY44TEOS7nGqH1uMU2PsK4zL20PnUzcj33q+1jsw2Pup3gEV82gZAnmPGD8BQ 081GU/EYiU/g3vtyCrdgeUfzFj04mLg03FuoqCiyZqUdckC0HZ+EmOdjAabygFaDyP6b cAZoRPVY6m/PTIxtpFEnxmwrTX4MYTopXEIjcePU74QVOTx2wABOxMV61H2ZhIX7WPQ1 IX3A== X-Gm-Message-State: AHPjjUiQLUB+ciX5K1djaw9cZEh1wfXPMQewj6+TnbM4/oJcqTGgHJCO Pdwb4AenpQ+UfAitl26yNA== X-Google-Smtp-Source: ADKCNb78iWc9rFMuPz7Pz7AUjHbOmTIppXkJMKmOXYgdM85mwYnXz0W75UqSmXn4/v8Jbqg3GBlZOg== X-Received: by 10.223.198.202 with SMTP id c10mr17906287wrh.230.1505388166486; Thu, 14 Sep 2017 04:22:46 -0700 (PDT) Received: from localhost (92.40.248.70.threembb.co.uk. [92.40.248.70]) by smtp.gmail.com with ESMTPSA id p199sm1489382wmb.28.2017.09.14.04.22.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Sep 2017 04:22:45 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Add a vect_worthwhile_without_simd_p helper routine Date: Thu, 14 Sep 2017 12:22:44 +0100 Message-ID: <87shfpwmm3.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 The vectoriser sometimes considers lowering "vector" operations into N scalar word operations. This N needs to be fixed at compile time, so the condition guarding it needs to change when variable-lengh vectors are added. This patch puts the condition into a helper routine so that there's only one place to update. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. OK to install? Richard 2017-09-14 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-vectorizer.h (vect_min_worthwhile_factor): Delete. (vect_worthwhile_without_simd_p): Declare. * tree-vect-loop.c (vect_worthwhile_without_simd_p): New function. (vectorizable_reduction): Use it. * tree-vect-stmts.c (vectorizable_shift): Likewise. (vectorizable_operation): Likewise. Index: gcc/tree-vectorizer.h =================================================================== --- gcc/tree-vectorizer.h 2017-09-14 11:27:50.352072753 +0100 +++ gcc/tree-vectorizer.h 2017-09-14 11:28:27.080519923 +0100 @@ -1230,7 +1230,7 @@ extern bool vectorizable_reduction (gimp extern bool vectorizable_induction (gimple *, gimple_stmt_iterator *, gimple **, slp_tree); extern tree get_initial_def_for_reduction (gimple *, tree, tree *); -extern int vect_min_worthwhile_factor (enum tree_code); +extern bool vect_worthwhile_without_simd_p (vec_info *, tree_code); extern int vect_get_known_peeling_cost (loop_vec_info, int, int *, stmt_vector_for_cost *, stmt_vector_for_cost *, Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2017-09-14 11:27:50.351164919 +0100 +++ gcc/tree-vect-loop.c 2017-09-14 11:28:27.079519923 +0100 @@ -6030,8 +6030,7 @@ vectorizable_reduction (gimple *stmt, gi dump_printf (MSG_NOTE, "op not supported by target.\n"); if (GET_MODE_SIZE (vec_mode) != UNITS_PER_WORD - || LOOP_VINFO_VECT_FACTOR (loop_vinfo) - < vect_min_worthwhile_factor (code)) + || !vect_worthwhile_without_simd_p (loop_vinfo, code)) return false; if (dump_enabled_p ()) @@ -6040,8 +6039,7 @@ vectorizable_reduction (gimple *stmt, gi /* Worthwhile without SIMD support? */ if (!VECTOR_MODE_P (TYPE_MODE (vectype_in)) - && LOOP_VINFO_VECT_FACTOR (loop_vinfo) - < vect_min_worthwhile_factor (code)) + && !vect_worthwhile_without_simd_p (loop_vinfo, code)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -6492,6 +6490,18 @@ vect_min_worthwhile_factor (enum tree_co } } +/* Return true if VINFO indicates we are doing loop vectorization and if + it is worth decomposing CODE operations into scalar operations for + that loop's vectorization factor. */ + +bool +vect_worthwhile_without_simd_p (vec_info *vinfo, tree_code code) +{ + loop_vec_info loop_vinfo = dyn_cast (vinfo); + return (loop_vinfo + && (LOOP_VINFO_VECT_FACTOR (loop_vinfo) + >= vect_min_worthwhile_factor (code))); +} /* Function vectorizable_induction Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c 2017-09-14 11:27:50.352072753 +0100 +++ gcc/tree-vect-stmts.c 2017-09-14 11:28:27.080519923 +0100 @@ -4869,7 +4869,6 @@ vectorizable_shift (gimple *stmt, gimple bool scalar_shift_arg = true; bb_vec_info bb_vinfo = STMT_VINFO_BB_VINFO (stmt_info); vec_info *vinfo = stmt_info->vinfo; - int vf; if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo) return false; @@ -4937,11 +4936,6 @@ vectorizable_shift (gimple *stmt, gimple return false; } - if (loop_vinfo) - vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); - else - vf = 1; - /* Multiple types in SLP are handled by creating the appropriate number of vectorized stmts for each SLP node. Hence, NCOPIES is always 1 in case of SLP. */ @@ -5086,8 +5080,8 @@ vectorizable_shift (gimple *stmt, gimple "op not supported by target.\n"); /* Check only during analysis. */ if (GET_MODE_SIZE (vec_mode) != UNITS_PER_WORD - || (vf < vect_min_worthwhile_factor (code) - && !vec_stmt)) + || (!vec_stmt + && !vect_worthwhile_without_simd_p (vinfo, code))) return false; if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, @@ -5095,9 +5089,9 @@ vectorizable_shift (gimple *stmt, gimple } /* Worthwhile without SIMD support? Check only during analysis. */ - if (!VECTOR_MODE_P (TYPE_MODE (vectype)) - && vf < vect_min_worthwhile_factor (code) - && !vec_stmt) + if (!vec_stmt + && !VECTOR_MODE_P (TYPE_MODE (vectype)) + && !vect_worthwhile_without_simd_p (vinfo, code)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -5241,7 +5235,6 @@ vectorizable_operation (gimple *stmt, gi tree vop0, vop1, vop2; bb_vec_info bb_vinfo = STMT_VINFO_BB_VINFO (stmt_info); vec_info *vinfo = stmt_info->vinfo; - int vf; if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo) return false; @@ -5368,11 +5361,6 @@ vectorizable_operation (gimple *stmt, gi } } - if (loop_vinfo) - vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); - else - vf = 1; - /* Multiple types in SLP are handled by creating the appropriate number of vectorized stmts for each SLP node. Hence, NCOPIES is always 1 in case of SLP. */ @@ -5414,7 +5402,7 @@ vectorizable_operation (gimple *stmt, gi "op not supported by target.\n"); /* Check only during analysis. */ if (GET_MODE_SIZE (vec_mode) != UNITS_PER_WORD - || (!vec_stmt && vf < vect_min_worthwhile_factor (code))) + || (!vec_stmt && !vect_worthwhile_without_simd_p (vinfo, code))) return false; if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, @@ -5424,7 +5412,7 @@ vectorizable_operation (gimple *stmt, gi /* Worthwhile without SIMD support? Check only during analysis. */ if (!VECTOR_MODE_P (vec_mode) && !vec_stmt - && vf < vect_min_worthwhile_factor (code)) + && !vect_worthwhile_without_simd_p (vinfo, code)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,