From patchwork Fri Oct 12 16:36:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renlin Li X-Patchwork-Id: 983182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487472-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=foss.arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="j5nnjnsu"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42WtlV2ysjz9s3Z for ; Sat, 13 Oct 2018 03:36:54 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Ha5l0ypeQgdJRnJVMqWiDrWZc6NSfmXjlN/FIjlnpXVxEyFke8 tNn0zwj19D4WauKBnYXcrfL+PL5Vk2SaAytUqIfzL7qCXFmtq6EPdgzMtnUtjFWm fpJuYFDc14W8WzBtV2FYLHJ0oEwx86LR3LPbk3009kLwvtxODOSkzHC/U= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=CyKGZjLo9eIvhLt2QFEHJm/gf1M=; b=j5nnjnsufhFbhgbYM8c2 M0X/G/qVdl3cmI7VHUv09LTOqgu9SA/lMBClMFFtHFlWWs30W3EITRjq0pq/GMM1 kDrMlrzTguJRlPrNRkM53U0RA1RdIdtucY3D7PnmFzPgV/igfUAg0Vnq8pyrVzC3 QDsJL7GKntxv3sAVUnabfvw= Received: (qmail 43938 invoked by alias); 12 Oct 2018 16:36:46 -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 43911 invoked by uid 89); 12 Oct 2018 16:36:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH autolearn=ham version=3.3.2 spammy=optproblemh, opt-problem.h, UD:opt-problem.h, 87563 X-HELO: foss.arm.com Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Oct 2018 16:36:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AA442F; Fri, 12 Oct 2018 09:36:40 -0700 (PDT) Received: from [10.2.206.82] (e109742-lin.cambridge.arm.com [10.2.206.82]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 117BD3F5D3; Fri, 12 Oct 2018 09:36:39 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" , Richard Sandiford , Ramana Radhakrishnan From: Renlin Li Subject: [PR87563][AARCH64-SVE]: Don't keep ifcvt loop when COND_ ifn could not be vectorized. Message-ID: <4bf6b224-f0ce-9a1b-adde-ba318cf13f9e@foss.arm.com> Date: Fri, 12 Oct 2018 17:36:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi all, ifcvt will created versioned loop and it will permissively generate scalar COND_ ifn. If in the loop vectorize pass, COND_ could not get vectorized, the if-converted loop should be abandoned when the target doesn't support such ifn. As currently, COND_ is only used by aarch64 sve extension, I only run the aarch64-sve testsuites, no change to the result. Okay to commit? Regards, Renlin gcc/ChangeLog: 2018-10-12 Renlin Li PR target/87563 * tree-vectorizer.c (try_vectorize_loop_1): Don't use if-conversioned loop when it contains ifn with types not supported by backend. * internal-fn.c (expand_direct_optab_fn): Add an assert. (direct_internal_fn_supported_p): New helper function. * internal-fn.h (direct_internal_fn_supported_p): Declare. gcc/testsuite/ChangeLog: 2018-10-12 Renlin Li PR target/87563 * gcc.target/aarch64/sve/pr87563.c: New. diff --git a/gcc/internal-fn.h b/gcc/internal-fn.h index 99765cf407acc7d65356b156e91f9dc51f1dba34..ff3bace1ce643ee10e1f776efffa01af31b6bbe7 100644 --- a/gcc/internal-fn.h +++ b/gcc/internal-fn.h @@ -187,6 +187,7 @@ extern bool direct_internal_fn_supported_p (internal_fn, tree_pair, optimization_type); extern bool direct_internal_fn_supported_p (internal_fn, tree, optimization_type); +extern bool direct_internal_fn_supported_p (gcall *, optimization_type); /* Return true if FN is supported for types TYPE0 and TYPE1 when the optimization type is OPT_TYPE. The types are those associated with diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 34d4f9efab9a45e0a9e3622f37dab0fa417b76f7..d082dd5054fa7175ffd3a53414b1ef42a1fca14e 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -2890,6 +2890,7 @@ expand_direct_optab_fn (internal_fn fn, gcall *stmt, direct_optab optab, tree_pair types = direct_internal_fn_types (fn, stmt); insn_code icode = direct_optab_handler (optab, TYPE_MODE (types.first)); + gcc_assert (icode != CODE_FOR_nothing); tree lhs = gimple_call_lhs (stmt); rtx lhs_rtx = NULL_RTX; @@ -3183,6 +3184,17 @@ direct_internal_fn_supported_p (internal_fn fn, tree type, return direct_internal_fn_supported_p (fn, tree_pair (type, type), opt_type); } +/* Return true if the STMT is supported when the optimization type is OPT_TYPE, + given that STMT is a call to a direct internal function. */ + +bool +direct_internal_fn_supported_p (gcall *stmt, optimization_type opt_type) +{ + internal_fn fn = gimple_call_internal_fn (stmt); + tree_pair types = direct_internal_fn_types (fn, stmt); + return direct_internal_fn_supported_p (fn, types, opt_type); +} + /* If FN is commutative in two consecutive arguments, return the index of the first, otherwise return -1. */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr87563.c b/gcc/testsuite/gcc.target/aarch64/sve/pr87563.c new file mode 100644 index 0000000000000000000000000000000000000000..83553b7ceea7199b5afb9f5adab50f15f9e41d55 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr87563.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -fdump-tree-ifcvt-details -fdump-tree-vect" } */ + +int a, b, c, *e; +int d[2]; + +void f () +{ + while (c) + { + d[0] = 4; + d[1] = 4; + *e = b == 0 ? 0 : a / b; + } +} + +/* { dg-final { scan-tree-dump "COND_DIV" "ifcvt" } } */ +/* { dg-final { scan-tree-dump-not "COND_DIV" "vect" } } */ diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index 747fb67ba13e80309377e66945a40f5e48f186c5..e70bd60493b22699b6873463281cc337a888f887 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -80,6 +80,7 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "gimple-pretty-print.h" #include "opt-problem.h" +#include "internal-fn.h" /* Loop or bb location, with hotness information. */ @@ -898,23 +899,30 @@ try_vectorize_loop_1 (hash_table *&simduid_to_vf_htab, && ! loop->inner) { basic_block bb = loop->header; - bool has_mask_load_store = false; + bool require_loop_vectorize = false; for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); - if (is_gimple_call (stmt) - && gimple_call_internal_p (stmt) - && (gimple_call_internal_fn (stmt) == IFN_MASK_LOAD - || gimple_call_internal_fn (stmt) == IFN_MASK_STORE)) + gcall *call = dyn_cast (stmt); + if (call && gimple_call_internal_p (call)) { - has_mask_load_store = true; - break; + internal_fn ifn = gimple_call_internal_fn (call); + if (ifn == IFN_MASK_LOAD || ifn == IFN_MASK_STORE + /* Don't keep the if-converted parts when the ifn with + specifc type is not supported by the backend. */ + || (direct_internal_fn_p (ifn) + && !direct_internal_fn_supported_p + (call, OPTIMIZE_FOR_SPEED))) + { + require_loop_vectorize = true; + break; + } } gimple_set_uid (stmt, -1); gimple_set_visited (stmt, false); } - if (! has_mask_load_store && vect_slp_bb (bb)) + if (!require_loop_vectorize && vect_slp_bb (bb)) { dump_printf_loc (MSG_NOTE, vect_location, "basic block vectorized\n");