From patchwork Thu Jul 13 09:03:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107656 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1945377qge; Thu, 13 Jul 2017 02:05:19 -0700 (PDT) X-Received: by 10.84.229.6 with SMTP id b6mr8691957plk.247.1499936719815; Thu, 13 Jul 2017 02:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499936719; cv=none; d=google.com; s=arc-20160816; b=WAR/zyxxvxI8DzVUE5KWC2yh7YjNF73boTnZsJ+ex7KXK9K0U6g4xw/LLL+sFjBMBR wRvMBkFa4Q4GDj8dQmaIitOosH6z8BfbaFlg1Gm5ZUW6lp2wAG3V9M+fW+Wk4ioONS5w kCVbRaaVAlkpof6THdOymYWE6spA9DSER39bxgERveqaz2L8rRXcDmqLksgpqgXQXC2y 3I3CSC+ajPtQ0ufAtdNHjXHPy7zP5XIuUb4qvMBC9yA+5j+U46/zNmXce6iXAEYHdc5U LMS9f7F8iRKiYdVZsoeLyb/ote+F8fODOGHiWOX9kJ5CJqX26Qpt7mx/WdKWrfK7iYkb l9NQ== 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=nJDRMBHvUQG/vS7ppXxGYXPntW2gyXYAhA46XvRE8rg=; b=gwxBk/1qQ7IkiRaW04T4PY4l61z0AzbwAfov+5AX1BhlGwtIyrCKViKu/giJqg9VUk ks7r2qQTgAh14GZkOrvM95g7DuFuieBoJ0DVdQ5sOT44MOz2wMpiLLesyspMJqDxImk4 gQcXAotOL5zBl4sjOfMA/cidGeLHcniTM/XD3ZQ6sn3Dgj+B6zj+pU4b8c6T9osT1nRj 3SY4vDS598tS43Z2nzVvqDtxFTRcYDgaBo9b10WHsLyPcdGjvjY6nTvEHzb5vkOc7SyT It6H2/qfguATQ11aEBSTqWoQNmHsDFWlGwnwrtR6BU3oyKU/nGshKMoyeEOZk1XyyVmA SVhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=y2Su4QV3; spf=pass (google.com: domain of gcc-patches-return-458061-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458061-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 v18si3800457pfi.87.2017.07.13.02.05.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 02:05:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458061-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.b=y2Su4QV3; spf=pass (google.com: domain of gcc-patches-return-458061-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458061-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=ykOyoatBbpS8ZITPIxqB50ZteVPcq QExkAUhL9SkKkWcYMkqxA0+Yg8kpnDl3uFZJbdGVpgqrqqVJ46FpieRnGtSKjJm/ RBnVkvGuqN7AzemdkpsrSueeypZVscItUcg4GmpOQpVrJ5IbCQszA/DO1wHkFvNl D3i/NDFgU5KB+c= 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=AVJY4y3k9HtLmXAIBGPxyemVVPM=; b=y2S u4QV35czGHyCRhOJaE6AP28iWE9TkYH0TeNE2dQrFcllq5Or+dgb35uOhB/fOVR6 +l28PmUZZyDuLY5FgUwnVEmBluL6YmX7xfmMEYVPs7QhNhwVSnRGLSAa4PoUZatG 7cqer6X5nIyiEZUp0DsZ8LQNuFbBIGN+f54PKSLc= Received: (qmail 50616 invoked by alias); 13 Jul 2017 09:03:32 -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 49812 invoked by uid 89); 13 Jul 2017 09:03:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 09:03:28 +0000 Received: by mail-wm0-f51.google.com with SMTP id f67so18618785wmh.1 for ; Thu, 13 Jul 2017 02:03:28 -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=nJDRMBHvUQG/vS7ppXxGYXPntW2gyXYAhA46XvRE8rg=; b=grz/HyloEgfmqetrU0MesRsNQe7hKR8UJATQ5+0dYSUUusK5WzpcRoCbw6dprf2uin NKDRvqz9i3NCpFLinaBhtCcFwZLkqwN+NsTnA/tVovpQQAnJmcMiyzEXOiw700UKMWJy GndUMATptuc97lWfs1Mm9ciyzp4s1b0gHnPfPR8Q7RQbcZ++twPSdxZ3XrfwhOUn3Ypm TbYaNzXJREobmFRokMKGwASGg38VqwmDp/jU72vR0XCv1rX7H9eQnJEzjUk4ivvJpNd/ 0B/ibmcydhuC9qjpqt00ARJFAuaUIhWfju7NAu5guAisqD1/vruT0Qsk9/E2sOhMlr1t qEnw== X-Gm-Message-State: AIVw112EHrbDwoJ7GNxdhYJCmTkNwrjBVs2+j0Kaw4eSKxtaLQr09ObB VKtyfXVc2RG5FhPe1hs2bw== X-Received: by 10.28.150.139 with SMTP id y133mr1201853wmd.61.1499936605947; Thu, 13 Jul 2017 02:03:25 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id p27sm5891348wmf.23.2017.07.13.02.03.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 02:03:25 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [70/77] Make expand_fix/float check for scalar modes References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 10:03:23 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <87r2xkbtes.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 The expand_float code: /* Unsigned integer, and no way to convert directly. Convert as signed, then unconditionally adjust the result. */ and the expand_fix code: /* For an unsigned conversion, there is one more way to do it. If we have a signed conversion, we generate code that compares the real value to the largest representable positive number. If if is smaller, the conversion is done normally. Otherwise, subtract one plus the highest signed number, convert, and add it back. are restricted to scalars, since the expansion branches on a comparison of the value. This patch makes that explicit. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * optabs.c (expand_float): Explicitly check for scalars before using a branching expansion. (expand_fix): Likewise. Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2017-07-13 09:18:53.274650323 +0100 +++ gcc/optabs.c 2017-07-13 09:18:56.346425666 +0100 @@ -4635,6 +4635,7 @@ expand_float (rtx to, rtx from, int unsi { enum insn_code icode; rtx target = to; + scalar_mode from_mode, to_mode; machine_mode fmode, imode; bool can_do_signed = false; @@ -4684,7 +4685,10 @@ expand_float (rtx to, rtx from, int unsi /* Unsigned integer, and no way to convert directly. Convert as signed, then unconditionally adjust the result. */ - if (unsignedp && can_do_signed) + if (unsignedp + && can_do_signed + && is_a (GET_MODE (to), &to_mode) + && is_a (GET_MODE (from), &from_mode)) { rtx_code_label *label = gen_label_rtx (); rtx temp; @@ -4694,19 +4698,19 @@ expand_float (rtx to, rtx from, int unsi least as wide as the target. Using FMODE will avoid rounding woes with unsigned values greater than the signed maximum value. */ - FOR_EACH_MODE_FROM (fmode, GET_MODE (to)) - if (GET_MODE_PRECISION (GET_MODE (from)) < GET_MODE_BITSIZE (fmode) - && can_float_p (fmode, GET_MODE (from), 0) != CODE_FOR_nothing) + FOR_EACH_MODE_FROM (fmode, to_mode) + if (GET_MODE_PRECISION (from_mode) < GET_MODE_BITSIZE (fmode) + && can_float_p (fmode, from_mode, 0) != CODE_FOR_nothing) break; if (fmode == VOIDmode) { /* There is no such mode. Pretend the target is wide enough. */ - fmode = GET_MODE (to); + fmode = to_mode; /* Avoid double-rounding when TO is narrower than FROM. */ if ((significand_size (fmode) + 1) - < GET_MODE_PRECISION (GET_MODE (from))) + < GET_MODE_PRECISION (from_mode)) { rtx temp1; rtx_code_label *neglabel = gen_label_rtx (); @@ -4718,7 +4722,7 @@ expand_float (rtx to, rtx from, int unsi || GET_MODE (target) != fmode) target = gen_reg_rtx (fmode); - imode = GET_MODE (from); + imode = from_mode; do_pending_stack_adjust (); /* Test whether the sign bit is set. */ @@ -4758,7 +4762,7 @@ expand_float (rtx to, rtx from, int unsi /* If we are about to do some arithmetic to correct for an unsigned operand, do it in a pseudo-register. */ - if (GET_MODE (to) != fmode + if (to_mode != fmode || !REG_P (to) || REGNO (to) < FIRST_PSEUDO_REGISTER) target = gen_reg_rtx (fmode); @@ -4769,11 +4773,11 @@ expand_float (rtx to, rtx from, int unsi correct its value by 2**bitwidth. */ do_pending_stack_adjust (); - emit_cmp_and_jump_insns (from, const0_rtx, GE, NULL_RTX, GET_MODE (from), + emit_cmp_and_jump_insns (from, const0_rtx, GE, NULL_RTX, from_mode, 0, label); - real_2expN (&offset, GET_MODE_PRECISION (GET_MODE (from)), fmode); + real_2expN (&offset, GET_MODE_PRECISION (from_mode), fmode); temp = expand_binop (fmode, add_optab, target, const_double_from_real_value (offset, fmode), target, 0, OPTAB_LIB_WIDEN); @@ -4901,11 +4905,14 @@ expand_fix (rtx to, rtx from, int unsign 2^63. The subtraction of 2^63 should not generate any rounding as it simply clears out that bit. The rest is trivial. */ - if (unsignedp && GET_MODE_PRECISION (GET_MODE (to)) <= HOST_BITS_PER_WIDE_INT) + scalar_int_mode to_mode; + if (unsignedp + && is_a (GET_MODE (to), &to_mode) + && HWI_COMPUTABLE_MODE_P (to_mode)) FOR_EACH_MODE_FROM (fmode, GET_MODE (from)) - if (CODE_FOR_nothing != can_fix_p (GET_MODE (to), fmode, 0, &must_trunc) + if (CODE_FOR_nothing != can_fix_p (to_mode, fmode, 0, &must_trunc) && (!DECIMAL_FLOAT_MODE_P (fmode) - || GET_MODE_BITSIZE (fmode) > GET_MODE_PRECISION (GET_MODE (to)))) + || GET_MODE_BITSIZE (fmode) > GET_MODE_PRECISION (to_mode))) { int bitsize; REAL_VALUE_TYPE offset; @@ -4913,7 +4920,7 @@ expand_fix (rtx to, rtx from, int unsign rtx_code_label *lab1, *lab2; rtx_insn *insn; - bitsize = GET_MODE_PRECISION (GET_MODE (to)); + bitsize = GET_MODE_PRECISION (to_mode); real_2expN (&offset, bitsize - 1, fmode); limit = const_double_from_real_value (offset, fmode); lab1 = gen_label_rtx (); @@ -4939,10 +4946,10 @@ expand_fix (rtx to, rtx from, int unsign target = expand_binop (GET_MODE (from), sub_optab, from, limit, NULL_RTX, 0, OPTAB_LIB_WIDEN); expand_fix (to, target, 0); - target = expand_binop (GET_MODE (to), xor_optab, to, + target = expand_binop (to_mode, xor_optab, to, gen_int_mode (HOST_WIDE_INT_1 << (bitsize - 1), - GET_MODE (to)), + to_mode), to, 1, OPTAB_LIB_WIDEN); if (target != to) @@ -4950,12 +4957,12 @@ expand_fix (rtx to, rtx from, int unsign emit_label (lab2); - if (optab_handler (mov_optab, GET_MODE (to)) != CODE_FOR_nothing) + if (optab_handler (mov_optab, to_mode) != CODE_FOR_nothing) { /* Make a place for a REG_NOTE and add it. */ insn = emit_move_insn (to, to); set_dst_reg_note (insn, REG_EQUAL, - gen_rtx_fmt_e (UNSIGNED_FIX, GET_MODE (to), + gen_rtx_fmt_e (UNSIGNED_FIX, to_mode, copy_rtx (from)), to); }