From patchwork Wed Oct 23 11:06:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1182060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-511567-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KR6WTyao"; 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 46yncs2RZXz9sCJ for ; Wed, 23 Oct 2019 22:06:35 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=fId9Rzi/Hw/3phH/TyvtsVe57VXbomJyl8TzunRcT7Q8oYOU0lrFp YVRmqmaIi9ns/m+IXpzJl9SGkYfuWKVCGizNhpUSVSCiFkfIOhi3fJRt3/Fzh+Lj CpJvxCA+UzMIY3oDwcRbqn9wyeBVoEasiHB17tAMZwRTvHR4aV9hi8= 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=318cuNRLjm0DErwSg7ueqkvX4D4=; b=KR6WTyao5n6EwPB76xWC VHSKXoeoZceIEZcA6VGpj0VExONW5IT+EA/3IUfGowkChC+HrK4U0OoABYIA3aJu Ddu2cJRgH6eh199WR/O7C4LGIs78chkUXTtyLtKcAxuGRLArZ9BoUthJjMcZkuOr k+K5pZ6INfAMrtILxXYfGMY= Received: (qmail 95129 invoked by alias); 23 Oct 2019 11:06:25 -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 95073 invoked by uid 89); 23 Oct 2019 11:06:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.1 spammy=17617, 2019-10-08 X-HELO: foss.arm.com Received: from Unknown (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Oct 2019 11:06:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2DF07494 for ; Wed, 23 Oct 2019 04:06:15 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BE3903F718 for ; Wed, 23 Oct 2019 04:06:14 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Replace mode_for_int_vector with related_int_vector_mode Date: Wed, 23 Oct 2019 12:06:13 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes mode_for_int_vector, like mode_for_vector, can sometimes return an integer mode or an unsupported vector mode. But no callers are interested in that case, and only want supported vector modes. This patch therefore replaces mode_for_int_vector with related_int_vector_mode, which gives the target a chance to pick its preferred vector mode for the given element mode and size. Tested individually on aarch64-linux-gnu and as a series on x86_64-linux-gnu. OK to install? Richard 2019-10-23 Richard Sandiford gcc/ * machmode.h (mode_for_int_vector): Delete. (related_int_vector_mode): Declare. * stor-layout.c (mode_for_int_vector): Delete. (related_int_vector_mode): New function. * optabs.c (expand_vec_perm_1): Use related_int_vector_mode instead of mode_for_int_vector. (expand_vec_perm_const): Likewise. * config/aarch64/aarch64.c (aarch64_emit_approx_sqrt): Likewise. (aarch64_evpc_sve_tbl): Likewise. * config/s390/s390.c (s390_expand_vec_compare_cc): Likewise. (s390_expand_vcond): Likewise. Index: gcc/machmode.h =================================================================== --- gcc/machmode.h 2019-10-23 11:33:01.564510281 +0100 +++ gcc/machmode.h 2019-10-23 12:01:36.968336613 +0100 @@ -879,22 +879,9 @@ smallest_int_mode_for_size (poly_uint64 extern opt_scalar_int_mode int_mode_for_mode (machine_mode); extern opt_machine_mode bitwise_mode_for_mode (machine_mode); extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64); -extern opt_machine_mode mode_for_int_vector (unsigned int, poly_uint64); extern opt_machine_mode related_vector_mode (machine_mode, scalar_mode, poly_uint64 = 0); - -/* Return the integer vector equivalent of MODE, if one exists. In other - words, return the mode for an integer vector that has the same number - of bits as MODE and the same number of elements as MODE, with the - latter being 1 if MODE is scalar. The returned mode can be either - an integer mode or a vector mode. */ - -inline opt_machine_mode -mode_for_int_vector (machine_mode mode) -{ - return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode), - GET_MODE_NUNITS (mode)); -} +extern opt_machine_mode related_int_vector_mode (machine_mode); /* A class for iterating through possible bitfield modes. */ class bit_field_mode_iterator Index: gcc/stor-layout.c =================================================================== --- gcc/stor-layout.c 2019-10-23 11:33:01.564510281 +0100 +++ gcc/stor-layout.c 2019-10-23 12:01:36.972336585 +0100 @@ -515,21 +515,6 @@ mode_for_vector (scalar_mode innermode, return opt_machine_mode (); } -/* Return the mode for a vector that has NUNITS integer elements of - INT_BITS bits each, if such a mode exists. The mode can be either - an integer mode or a vector mode. */ - -opt_machine_mode -mode_for_int_vector (unsigned int int_bits, poly_uint64 nunits) -{ - scalar_int_mode int_mode; - machine_mode vec_mode; - if (int_mode_for_size (int_bits, 0).exists (&int_mode) - && mode_for_vector (int_mode, nunits).exists (&vec_mode)) - return vec_mode; - return opt_machine_mode (); -} - /* If a piece of code is using vector mode VECTOR_MODE and also wants to operate on elements of mode ELEMENT_MODE, return the vector mode it should use for those elements. If NUNITS is nonzero, ensure that @@ -550,6 +535,26 @@ related_vector_mode (machine_mode vector return targetm.vectorize.related_mode (vector_mode, element_mode, nunits); } +/* If a piece of code is using vector mode VECTOR_MODE and also wants + to operate on integer vectors with the same element size and number + of elements, return the vector mode it should use. Return an empty + opt_machine_mode if there is no supported vector mode with the + required properties. + + Unlike mode_for_vector. any returned mode is guaranteed to satisfy + both VECTOR_MODE_P and targetm.vector_mode_supported_p. */ + +opt_machine_mode +related_int_vector_mode (machine_mode vector_mode) +{ + gcc_assert (VECTOR_MODE_P (vector_mode)); + scalar_int_mode int_mode; + if (int_mode_for_mode (GET_MODE_INNER (vector_mode)).exists (&int_mode)) + return related_vector_mode (vector_mode, int_mode, + GET_MODE_NUNITS (vector_mode)); + return opt_machine_mode (); +} + /* Return the alignment of MODE. This will be bounded by 1 and BIGGEST_ALIGNMENT. */ Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2019-10-08 09:23:31.582531825 +0100 +++ gcc/optabs.c 2019-10-23 12:01:36.972336585 +0100 @@ -5542,7 +5542,7 @@ expand_vec_perm_1 (enum insn_code icode, class expand_operand ops[4]; gcc_assert (GET_MODE_CLASS (smode) == MODE_VECTOR_INT - || mode_for_int_vector (tmode).require () == smode); + || related_int_vector_mode (tmode).require () == smode); create_output_operand (&ops[0], target, tmode); create_input_operand (&ops[3], sel, smode); @@ -5679,8 +5679,7 @@ expand_vec_perm_const (machine_mode mode /* The optabs are only defined for selectors with the same width as the values being permuted. */ machine_mode required_sel_mode; - if (!mode_for_int_vector (mode).exists (&required_sel_mode) - || !VECTOR_MODE_P (required_sel_mode)) + if (!related_int_vector_mode (mode).exists (&required_sel_mode)) { delete_insns_since (last); return NULL_RTX; Index: gcc/config/aarch64/aarch64.c =================================================================== --- gcc/config/aarch64/aarch64.c 2019-10-23 11:30:57.553389936 +0100 +++ gcc/config/aarch64/aarch64.c 2019-10-23 12:01:36.964336643 +0100 @@ -1761,7 +1761,7 @@ aarch64_sve_element_int_mode (machine_mo } /* Return the integer vector mode associated with SVE mode MODE. - Unlike mode_for_int_vector, this can handle the case in which + Unlike related_int_vector_mode, this can handle the case in which MODE is a predicate (and thus has a different total size). */ static machine_mode @@ -11829,7 +11829,7 @@ aarch64_emit_approx_sqrt (rtx dst, rtx s gcc_assert (use_rsqrt_p (mode)); machine_mode mmsk = (VECTOR_MODE_P (mode) - ? mode_for_int_vector (mode).require () + ? related_int_vector_mode (mode).require () : int_mode_for_mode (mode).require ()); rtx xmsk = gen_reg_rtx (mmsk); if (!recp) @@ -18232,7 +18232,7 @@ aarch64_evpc_sve_tbl (struct expand_vec_ if (d->testing_p) return true; - machine_mode sel_mode = mode_for_int_vector (d->vmode).require (); + machine_mode sel_mode = related_int_vector_mode (d->vmode).require (); rtx sel = vec_perm_indices_to_rtx (sel_mode, d->perm); if (d->one_vector_p) emit_unspec2 (d->target, UNSPEC_TBL, d->op0, force_reg (sel_mode, sel)); Index: gcc/config/s390/s390.c =================================================================== --- gcc/config/s390/s390.c 2019-10-11 15:43:55.047486939 +0100 +++ gcc/config/s390/s390.c 2019-10-23 12:01:36.968336613 +0100 @@ -6653,7 +6653,7 @@ s390_expand_vec_compare_cc (rtx target, case LE: cc_producer_mode = CCVFHEmode; code = GE; swap_p = true; break; default: gcc_unreachable (); } - scratch_mode = mode_for_int_vector (GET_MODE (cmp1)).require (); + scratch_mode = related_int_vector_mode (GET_MODE (cmp1)).require (); if (inv_p) all_p = !all_p; @@ -6759,7 +6759,7 @@ s390_expand_vcond (rtx target, rtx then, /* We always use an integral type vector to hold the comparison result. */ - result_mode = mode_for_int_vector (cmp_mode).require (); + result_mode = related_int_vector_mode (cmp_mode).require (); result_target = gen_reg_rtx (result_mode); /* We allow vector immediates as comparison operands that