From patchwork Mon Sep 4 11:36:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 111545 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp4114349ybm; Mon, 4 Sep 2017 04:37:24 -0700 (PDT) X-Received: by 10.99.163.65 with SMTP id v1mr153207pgn.310.1504525043961; Mon, 04 Sep 2017 04:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504525043; cv=none; d=google.com; s=arc-20160816; b=Gse+haTdAlN0lCISzzlwOjvSUJCbbeNQeJOCqFiNFqCv9kcVyyg53q/7F5HaF8yAA3 /yJe/kYCodB0v3SAqiQuQsN9d66CuD94A+3Klh9MFAecl75oHImjGpf26+LuJYHP0SPH Xu8VxYlJNlJuyaTa74pOlgqHAvD0rOOUhZKuw2lloMlT2W2snCSEE3DCnMqE3XwpHt7X LcwQ8LvGWxD96+9SaH59IgzlMvmjI7PB9zIVCU0r9ZTk+8BnG0/EugKK0ABc1tzja8XA KGehHbFpcBMKHk1TFI0B23Zom2FG1ayzXNMVic14s2be/wnZEAsm1e5k8bpZRiwI4iFn Iwvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :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=4NJc84hv5/lW5M+SJ/34CxEqJzbU4BWm8XxHGXdxBWM=; b=xe1NthAFQWhM3HPPqrSqc9jLD+5R3JHD9UwC39LT0U9oEN+sxpU6qifTr0vDcDKA5e JF8YCpmpKzQLI2GmoLj+CttYwHl7dLlrsuTQZtdwsT5eeQ04IsGL0oWPcH4wW6iUGf8S zL37pzMK1VP60ff4CkWIMf2lA0idC4DCmgD1KOC2jTZaNLvVr5396XJjlhu48CrjgrVW aRKn4NRj3vc8d02SyP3IwxtkkIYpIQUwXqB73U88eL+uRnySOPgX4JMyBIJL7UK0c0qJ K3iivCB8h6G4lqbHRpc7WSxm/qasgJrnRvQPmXTP2u8dN/4Mp86zP9IBQp44/ruUG9Wx FyMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=m5Up0aBe; spf=pass (google.com: domain of gcc-patches-return-461408-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-461408-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 v81si4793201pfi.547.2017.09.04.04.37.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Sep 2017 04:37:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-461408-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=m5Up0aBe; spf=pass (google.com: domain of gcc-patches-return-461408-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-461408-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:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=NvEIGPcS5+5fbRJKdco9VwV6lRgoi RzT/nqP41xSxOAaxzadIoKL3H8bK/+4L19QF93fgEEuav5jUu42vlPVTvcvrQPUi u5OdEAhv4UxaaP5qZ6LV6dFmg0uEEN7YNqgeLhO2VjYAz0yPoxyy/V8l2Ns87kQf hbcb52yc+6qghw= 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:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=qlvu87wq3CHWf9v3fC+djt0VZIc=; b=m5U p0aBeliDN7rfDafIGiyuweQBw8F36TiKKOkt/siUEWnNwmmL5JRMUCYk4iX5lzqQ Z4nTgDS1Lo/+xgfJ3iiAlPciohjYIb6tIn+eImqHfK7XI8fwNlEYi2Kxsmb8l+LM nJ8XaGv4QIooKfrtglpq2m53dsIR+Uyuwdw5J1Ho= Received: (qmail 99394 invoked by alias); 4 Sep 2017 11:37:09 -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 99381 invoked by uid 89); 4 Sep 2017 11:37:08 -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-wm0-f48.google.com Received: from mail-wm0-f48.google.com (HELO mail-wm0-f48.google.com) (74.125.82.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Sep 2017 11:37:03 +0000 Received: by mail-wm0-f48.google.com with SMTP id u26so1752670wma.0 for ; Mon, 04 Sep 2017 04:37:02 -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:references:date :in-reply-to:message-id:user-agent:mime-version; bh=4NJc84hv5/lW5M+SJ/34CxEqJzbU4BWm8XxHGXdxBWM=; b=OQGrc9G9yif0IhhbyKG/jVkv5NJRituB82x20PTYHQR3FK9QYN/b6uBymneW6kE4NK 40KhVPFmRVdBdg+JHHSmfnkaDRCAyLLjqf8yJuMoUIqIbnfjs6tpzbsN2GJpcfECWV1z AsXU73hq/NrjQ4XInZYdbM39EYCu77tZ/QE0HjGp3kIZi9H78Q9vIVXzx6W/tKNMRZZK 5MjreDNnclka5yMyV6Te8HrFDXjbspd2918lvHvjP9u/08FK/VFnvR3NPMgfJ3iJCGrv tjIjsndKWbEb5UwUG0Jph33lPaEjjBZjUmULt0x+FdVheMwPA3ypTEjDmkZMpc5xvFcl WBtA== X-Gm-Message-State: AHPjjUhbfBSRos0qJh1KMYIBA+im9UsnrbwTAGB7voamWHvliiPzjJYX zZqqH/pZjxu341DJV/lLGw== X-Google-Smtp-Source: ADKCNb6bToIWUArWBHKUE8rjKlfdksi73HSDxBzsN7QW5ocLVsnDLB1Iya090gMS2kjEHAy8Itba+g== X-Received: by 10.28.157.81 with SMTP id g78mr418028wme.102.1504525020983; Mon, 04 Sep 2017 04:37:00 -0700 (PDT) Received: from localhost (94.197.120.41.threembb.co.uk. [94.197.120.41]) by smtp.gmail.com with ESMTPSA id r92sm1132234wrb.37.2017.09.04.04.36.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Sep 2017 04:37:00 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [5/9] Add mode_for_int_vector helper functions References: <87tw0iiu51.fsf@linaro.org> Date: Mon, 04 Sep 2017 12:36:57 +0100 In-Reply-To: <87tw0iiu51.fsf@linaro.org> (Richard Sandiford's message of "Mon, 04 Sep 2017 12:24:26 +0100") Message-ID: <878thuitk6.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 There are at least a few places that want to create an integer vector with a specified element size and element count, or to create the integer equivalent of an existing mode. This patch adds helpers for doing that. The require ()s are all used in functions that go on to emit instructions that use the result as a vector mode. 2017-09-04 Richard Sandiford gcc/ * machmode.h (mode_for_int_vector): New function. * stor-layout.c (mode_for_int_vector): Likewise. * config/aarch64/aarch64.c (aarch64_emit_approx_sqrt): Use it. * config/powerpcspe/powerpcspe.c (rs6000_do_expand_vec_perm): Likewise. * config/rs6000/rs6000.c (rs6000_do_expand_vec_perm): Likewise. * config/s390/s390.c (s390_expand_vec_compare_cc): Likewise. (s390_expand_vcond): Likewise. Index: gcc/machmode.h =================================================================== --- gcc/machmode.h 2017-09-04 12:18:50.674859598 +0100 +++ gcc/machmode.h 2017-09-04 12:18:53.153306182 +0100 @@ -706,6 +706,21 @@ extern machine_mode bitwise_mode_for_mod extern machine_mode mode_for_vector (scalar_mode, unsigned); +extern opt_machine_mode mode_for_int_vector (unsigned int, unsigned int); + +/* 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)); +} + /* A class for iterating through possible bitfield modes. */ class bit_field_mode_iterator { Index: gcc/stor-layout.c =================================================================== --- gcc/stor-layout.c 2017-09-04 12:18:50.675762071 +0100 +++ gcc/stor-layout.c 2017-09-04 12:18:53.153306182 +0100 @@ -517,6 +517,23 @@ mode_for_vector (scalar_mode innermode, return 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, unsigned int nunits) +{ + scalar_int_mode int_mode; + if (int_mode_for_size (int_bits, 0).exists (&int_mode)) + { + machine_mode vec_mode = mode_for_vector (int_mode, nunits); + if (vec_mode != BLKmode) + return vec_mode; + } + return opt_machine_mode (); +} + /* Return the alignment of MODE. This will be bounded by 1 and BIGGEST_ALIGNMENT. */ Index: gcc/config/aarch64/aarch64.c =================================================================== --- gcc/config/aarch64/aarch64.c 2017-09-04 12:18:44.874165502 +0100 +++ gcc/config/aarch64/aarch64.c 2017-09-04 12:18:53.144272229 +0100 @@ -8282,9 +8282,6 @@ aarch64_emit_approx_sqrt (rtx dst, rtx s return false; } - machine_mode mmsk - = mode_for_vector (int_mode_for_mode (GET_MODE_INNER (mode)).require (), - GET_MODE_NUNITS (mode)); if (!recp) { if (!(flag_mlow_precision_sqrt @@ -8302,7 +8299,7 @@ aarch64_emit_approx_sqrt (rtx dst, rtx s /* Caller assumes we cannot fail. */ gcc_assert (use_rsqrt_p (mode)); - + machine_mode mmsk = mode_for_int_vector (mode).require (); rtx xmsk = gen_reg_rtx (mmsk); if (!recp) /* When calculating the approximate square root, compare the Index: gcc/config/powerpcspe/powerpcspe.c =================================================================== --- gcc/config/powerpcspe/powerpcspe.c 2017-09-04 12:18:44.919414816 +0100 +++ gcc/config/powerpcspe/powerpcspe.c 2017-09-04 12:18:53.148287319 +0100 @@ -38739,8 +38739,7 @@ rs6000_do_expand_vec_perm (rtx target, r imode = vmode; if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT) - imode = mode_for_vector - (int_mode_for_mode (GET_MODE_INNER (vmode)).require (), nelt); + imode = mode_for_int_vector (vmode).require (); x = gen_rtx_CONST_VECTOR (imode, gen_rtvec_v (nelt, perm)); x = expand_vec_perm (vmode, op0, op1, x, target); Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c 2017-09-04 12:18:44.929470219 +0100 +++ gcc/config/rs6000/rs6000.c 2017-09-04 12:18:53.151298637 +0100 @@ -35584,8 +35584,7 @@ rs6000_do_expand_vec_perm (rtx target, r imode = vmode; if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT) - imode = mode_for_vector - (int_mode_for_mode (GET_MODE_INNER (vmode)).require (), nelt); + imode = mode_for_int_vector (vmode).require (); x = gen_rtx_CONST_VECTOR (imode, gen_rtvec_v (nelt, perm)); x = expand_vec_perm (vmode, op0, op1, x, target); Index: gcc/config/s390/s390.c =================================================================== --- gcc/config/s390/s390.c 2017-09-04 11:50:24.561571751 +0100 +++ gcc/config/s390/s390.c 2017-09-04 12:18:53.153306182 +0100 @@ -6472,10 +6472,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_vector - (int_mode_for_mode (GET_MODE_INNER (GET_MODE (cmp1))).require (), - GET_MODE_NUNITS (GET_MODE (cmp1))); - gcc_assert (scratch_mode != BLKmode); + scratch_mode = mode_for_int_vector (GET_MODE (cmp1)).require (); if (inv_p) all_p = !all_p; @@ -6581,9 +6578,7 @@ s390_expand_vcond (rtx target, rtx then, /* We always use an integral type vector to hold the comparison result. */ - result_mode = mode_for_vector - (int_mode_for_mode (GET_MODE_INNER (cmp_mode)).require (), - GET_MODE_NUNITS (cmp_mode)); + result_mode = mode_for_int_vector (cmp_mode).require (); result_target = gen_reg_rtx (result_mode); /* We allow vector immediates as comparison operands that