From patchwork Thu Jul 13 08:55:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107634 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1937743qge; Thu, 13 Jul 2017 01:57:13 -0700 (PDT) X-Received: by 10.101.73.197 with SMTP id t5mr8131311pgs.160.1499936233736; Thu, 13 Jul 2017 01:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499936233; cv=none; d=google.com; s=arc-20160816; b=Wz4vYm8HwPp0gJnPEYpdwTJVLGGoILCMKpTQxMW9QzmAzM5wSeCMwgJSabRcZHYoew wJW8yDJA73JuP3LyPOg2SbDZTTZAVj4oNwIv+Lyqw3jdljQkc/beNNoe7BqrAByeLrO5 5WYETIBYB1IMlkYsNGLEm0iC8XnlxuN+OSQDkgZa3wY1tNJY9PkHCspaKzvgXv93VT4C 2qbCqRWyIK41N+9Z7KFBu3PBHs196tPBHVqddxrJxvYLoVVhMEUhRVWcJNUDW6Gk69yL qNoLZdGCFA//QKaA2n4uuw9zq5ZaqaDxXaZUq/gYuiL2yiwt2OHslq/DgAhp8SBBBlXh J6Jw== 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=G2Xy9gfqEa6BbUshq9299tI0RAj8gFsYpsBTEe9nKlQ=; b=NtJbr6WI1JYhybbwZkFxdMxDYTg6rNWaBCClzBrKr4m4nsFvmMayV5EPZIm2xkwSWW MQjIRvpNGTfmXZ+kxXfIEqR87yp/0lcLTsbyP3izO+KR/vnuWUUAZCkJY2FYazn4kZEo 68diHqnit8jZ8WuIY9IN34Mn9M15U85Y2FvMkBc3PzjCbWVDC2dRO2vA9+w/r2UFgsn8 ztpj1O3DdQ3te5+kkWSZMsLCMlQXrdkT6Cka3OflXUV2KGVVRJklazHP4HRVKNqzaygt E+jIoE+NF36U0d2ap7Fuc079LEAHP2wXGyysjSKKiwvJ8dIJ+L0kHyXXrQo34sBEuW9V 88bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=JBq9wG6H; spf=pass (google.com: domain of gcc-patches-return-458039-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458039-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 k15si4161329pln.461.2017.07.13.01.57.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 01:57:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458039-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=JBq9wG6H; spf=pass (google.com: domain of gcc-patches-return-458039-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458039-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=P//S7x2OvNw9HidKwkLMausp07ehi QzuccGMS+QKqmh82Cd/dgz2lsDjT8RsV4+yOCATxiWXUpDzEBFaRWaNC0iLp963T kEVhx6rtTZbhwEGWSUU4rzU9z8PLTxvqwFvI+4YiDd36oHt8dOQRjcID2Cnt+F76 nI4yTFZzOgF/rc= 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=ommkP8hXhRRgUESEvXMxFjxeHwM=; b=JBq 9wG6HxXkzr2wYt7B3pnvhhEFzqVDa903UA0WrJ9Rb0AHIYbD4qrxpJbvW7GzLZKO ZWY35Kvyyor8Vyl2hlnqMtpKhyBc47QwkGJ2SG/BVHhWyOSRZPUNDsAMKy2Mn8SZ C6Oelj6/D9sRtTK76UffO4/MKvkLPzoT7gZf47Js= Received: (qmail 109967 invoked by alias); 13 Jul 2017 08:55:39 -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 109115 invoked by uid 89); 13 Jul 2017 08:55:38 -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-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 08:55:33 +0000 Received: by mail-wm0-f50.google.com with SMTP id i127so18362846wma.0 for ; Thu, 13 Jul 2017 01:55:32 -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=G2Xy9gfqEa6BbUshq9299tI0RAj8gFsYpsBTEe9nKlQ=; b=dxsPkrYz2yLuWu2pIaL3+bJoNtKv15cC2cSk0Y/FfVIgSICCqbOKWtXyAQtM4KgElk DHIKHMCZm0LvzT40FGiig1W5dDYtZWuNTCESbali1kfOV9PK++PDq/MgLloiO6N78Qkq bgjb95OVwA/wpeVZck+pbm8uutKpvJyK0k0d87oA7H4rE45ZWd/I0XY1XHJ/oWVmZqnB E4n9DlXxpjAebH+CJbXZrRNIZEOPaV/F9v4E87kK9ijq0yude2CVxpXpPJeBztlZIcRa 3H2gc9392v3iXyCP+o+04GV3rEObfj9w+FmNNRodzGeFevq7YtuTj7ZdBgLNkMANDQLK A5kw== X-Gm-Message-State: AIVw111ZBpEVkjYZP6qNzmocjb4S7A+N60f9U1J7eulX1hztIHc8X/sX PXCcKMnA8XgQIcs2ZiG+1w== X-Received: by 10.28.66.153 with SMTP id k25mr1128003wmi.129.1499936130898; Thu, 13 Jul 2017 01:55:30 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id w198sm6122850wme.21.2017.07.13.01.55.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 01:55:30 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [48/77] Make subroutines of num_sign_bit_copies operate on scalar_int_mode References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 09:55:28 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <87eftkg1hb.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Similarly to the nonzero_bits patch, this one moves the mode class check and VOIDmode handling from num_sign_bit_copies1 to num_sign_bit_copies itself, then changes the subroutines to operate on scalar_int_modes. gcc/ 2017-07-13 Richard Sandiford Alan Hayward David Sherwood * rtlanal.c (num_sign_bit_copies): Handle VOIDmode here rather than in subroutines. Return 1 for non-integer modes. (cached_num_sign_bit_copies): Change the type of the mode parameter to scalar_int_mode. (num_sign_bit_copies1): Likewise. Remove early exit for other mode classes. Handle CONST_INT_P first and then check whether X also has a scalar integer mode. Check the same thing for inner registers of a SUBREG and for values that are being extended or truncated. Index: gcc/rtlanal.c =================================================================== --- gcc/rtlanal.c 2017-07-13 09:18:44.976290184 +0100 +++ gcc/rtlanal.c 2017-07-13 09:18:45.323262480 +0100 @@ -49,11 +49,12 @@ static unsigned HOST_WIDE_INT cached_non static unsigned HOST_WIDE_INT nonzero_bits1 (const_rtx, scalar_int_mode, const_rtx, machine_mode, unsigned HOST_WIDE_INT); -static unsigned int cached_num_sign_bit_copies (const_rtx, machine_mode, const_rtx, - machine_mode, +static unsigned int cached_num_sign_bit_copies (const_rtx, scalar_int_mode, + const_rtx, machine_mode, unsigned int); -static unsigned int num_sign_bit_copies1 (const_rtx, machine_mode, const_rtx, - machine_mode, unsigned int); +static unsigned int num_sign_bit_copies1 (const_rtx, scalar_int_mode, + const_rtx, machine_mode, + unsigned int); rtx_subrtx_bound_info rtx_all_subrtx_bounds[NUM_RTX_CODE]; rtx_subrtx_bound_info rtx_nonconst_subrtx_bounds[NUM_RTX_CODE]; @@ -4248,7 +4249,12 @@ nonzero_bits (const_rtx x, machine_mode unsigned int num_sign_bit_copies (const_rtx x, machine_mode mode) { - return cached_num_sign_bit_copies (x, mode, NULL_RTX, VOIDmode, 0); + if (mode == VOIDmode) + mode = GET_MODE (x); + scalar_int_mode int_mode; + if (!is_a (mode, &int_mode)) + return 1; + return cached_num_sign_bit_copies (x, int_mode, NULL_RTX, VOIDmode, 0); } /* Return true if nonzero_bits1 might recurse into both operands @@ -4815,8 +4821,8 @@ num_sign_bit_copies_binary_arith_p (cons first or the second level. */ static unsigned int -cached_num_sign_bit_copies (const_rtx x, machine_mode mode, const_rtx known_x, - machine_mode known_mode, +cached_num_sign_bit_copies (const_rtx x, scalar_int_mode mode, + const_rtx known_x, machine_mode known_mode, unsigned int known_ret) { if (x == known_x && mode == known_mode) @@ -4861,44 +4867,46 @@ cached_num_sign_bit_copies (const_rtx x, } /* Return the number of bits at the high-order end of X that are known to - be equal to the sign bit. X will be used in mode MODE; if MODE is - VOIDmode, X will be used in its own mode. The returned value will always - be between 1 and the number of bits in MODE. */ + be equal to the sign bit. X will be used in mode MODE. The returned + value will always be between 1 and the number of bits in MODE. */ static unsigned int -num_sign_bit_copies1 (const_rtx x, machine_mode mode, const_rtx known_x, +num_sign_bit_copies1 (const_rtx x, scalar_int_mode mode, const_rtx known_x, machine_mode known_mode, unsigned int known_ret) { enum rtx_code code = GET_CODE (x); - machine_mode inner_mode; + unsigned int bitwidth = GET_MODE_PRECISION (mode); int num0, num1, result; unsigned HOST_WIDE_INT nonzero; - /* If we weren't given a mode, use the mode of X. If the mode is still - VOIDmode, we don't know anything. Likewise if one of the modes is - floating-point. */ - - if (mode == VOIDmode) - mode = GET_MODE (x); + if (CONST_INT_P (x)) + { + /* If the constant is negative, take its 1's complement and remask. + Then see how many zero bits we have. */ + nonzero = UINTVAL (x) & GET_MODE_MASK (mode); + if (bitwidth <= HOST_BITS_PER_WIDE_INT + && (nonzero & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0) + nonzero = (~nonzero) & GET_MODE_MASK (mode); - gcc_checking_assert (mode != BLKmode); + return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1); + } - if (mode == VOIDmode || FLOAT_MODE_P (mode) || FLOAT_MODE_P (GET_MODE (x)) - || VECTOR_MODE_P (GET_MODE (x)) || VECTOR_MODE_P (mode)) + scalar_int_mode xmode, inner_mode; + if (!is_a (GET_MODE (x), &xmode)) return 1; + unsigned int xmode_width = GET_MODE_PRECISION (xmode); + /* For a smaller mode, just ignore the high bits. */ - unsigned int bitwidth = GET_MODE_PRECISION (mode); - if (bitwidth < GET_MODE_PRECISION (GET_MODE (x))) + if (bitwidth < xmode_width) { - num0 = cached_num_sign_bit_copies (x, GET_MODE (x), + num0 = cached_num_sign_bit_copies (x, xmode, known_x, known_mode, known_ret); - return MAX (1, - num0 - (int) (GET_MODE_PRECISION (GET_MODE (x)) - bitwidth)); + return MAX (1, num0 - (int) (xmode_width - bitwidth)); } - if (GET_MODE (x) != VOIDmode && bitwidth > GET_MODE_PRECISION (GET_MODE (x))) + if (bitwidth > xmode_width) { /* If this machine does not do all register operations on the entire register and MODE is wider than the mode of X, we can say nothing @@ -4909,8 +4917,8 @@ num_sign_bit_copies1 (const_rtx x, machi /* Likewise on machines that do, if the mode of the object is smaller than a word and loads of that size don't sign extend, we can say nothing about the high order bits. */ - if (GET_MODE_PRECISION (GET_MODE (x)) < BITS_PER_WORD - && load_extend_op (GET_MODE (x)) != SIGN_EXTEND) + if (xmode_width < BITS_PER_WORD + && load_extend_op (xmode) != SIGN_EXTEND) return 1; } @@ -4927,7 +4935,7 @@ num_sign_bit_copies1 (const_rtx x, machi we can do this only if the target does not support different pointer or address modes depending on the address space. */ if (target_default_pointer_address_modes_p () - && ! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode + && ! POINTERS_EXTEND_UNSIGNED && xmode == Pmode && mode == Pmode && REG_POINTER (x) && !targetm.have_ptr_extend ()) return GET_MODE_PRECISION (Pmode) - GET_MODE_PRECISION (ptr_mode) + 1; @@ -4952,21 +4960,10 @@ num_sign_bit_copies1 (const_rtx x, machi case MEM: /* Some RISC machines sign-extend all loads of smaller than a word. */ - if (load_extend_op (GET_MODE (x)) == SIGN_EXTEND) - return MAX (1, ((int) bitwidth - - (int) GET_MODE_PRECISION (GET_MODE (x)) + 1)); + if (load_extend_op (xmode) == SIGN_EXTEND) + return MAX (1, ((int) bitwidth - (int) xmode_width + 1)); break; - case CONST_INT: - /* If the constant is negative, take its 1's complement and remask. - Then see how many zero bits we have. */ - nonzero = UINTVAL (x) & GET_MODE_MASK (mode); - if (bitwidth <= HOST_BITS_PER_WIDE_INT - && (nonzero & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0) - nonzero = (~nonzero) & GET_MODE_MASK (mode); - - return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1); - case SUBREG: /* If this is a SUBREG for a promoted object that is sign-extended and we are looking at it in a wider mode, we know that at least the @@ -4976,37 +4973,38 @@ num_sign_bit_copies1 (const_rtx x, machi { num0 = cached_num_sign_bit_copies (SUBREG_REG (x), mode, known_x, known_mode, known_ret); - return MAX ((int) bitwidth - - (int) GET_MODE_PRECISION (GET_MODE (x)) + 1, - num0); + return MAX ((int) bitwidth - (int) xmode_width + 1, num0); } - /* For a smaller object, just ignore the high bits. */ - inner_mode = GET_MODE (SUBREG_REG (x)); - if (bitwidth <= GET_MODE_PRECISION (inner_mode)) + if (is_a (GET_MODE (SUBREG_REG (x)), &inner_mode)) { - num0 = cached_num_sign_bit_copies (SUBREG_REG (x), VOIDmode, - known_x, known_mode, known_ret); - return - MAX (1, num0 - (int) (GET_MODE_PRECISION (inner_mode) - bitwidth)); - } + /* For a smaller object, just ignore the high bits. */ + if (bitwidth <= GET_MODE_PRECISION (inner_mode)) + { + num0 = cached_num_sign_bit_copies (SUBREG_REG (x), inner_mode, + known_x, known_mode, + known_ret); + return MAX (1, num0 - (int) (GET_MODE_PRECISION (inner_mode) + - bitwidth)); + } - /* For paradoxical SUBREGs on machines where all register operations - affect the entire register, just look inside. Note that we are - passing MODE to the recursive call, so the number of sign bit copies - will remain relative to that mode, not the inner mode. */ - - /* This works only if loads sign extend. Otherwise, if we get a - reload for the inner part, it may be loaded from the stack, and - then we lose all sign bit copies that existed before the store - to the stack. */ - - if (WORD_REGISTER_OPERATIONS - && load_extend_op (inner_mode) == SIGN_EXTEND - && paradoxical_subreg_p (x) - && (MEM_P (SUBREG_REG (x)) || REG_P (SUBREG_REG (x)))) - return cached_num_sign_bit_copies (SUBREG_REG (x), mode, - known_x, known_mode, known_ret); + /* For paradoxical SUBREGs on machines where all register operations + affect the entire register, just look inside. Note that we are + passing MODE to the recursive call, so the number of sign bit + copies will remain relative to that mode, not the inner mode. */ + + /* This works only if loads sign extend. Otherwise, if we get a + reload for the inner part, it may be loaded from the stack, and + then we lose all sign bit copies that existed before the store + to the stack. */ + + if (WORD_REGISTER_OPERATIONS + && load_extend_op (inner_mode) == SIGN_EXTEND + && paradoxical_subreg_p (x) + && (MEM_P (SUBREG_REG (x)) || REG_P (SUBREG_REG (x)))) + return cached_num_sign_bit_copies (SUBREG_REG (x), mode, + known_x, known_mode, known_ret); + } break; case SIGN_EXTRACT: @@ -5015,15 +5013,18 @@ num_sign_bit_copies1 (const_rtx x, machi break; case SIGN_EXTEND: - return (bitwidth - GET_MODE_PRECISION (GET_MODE (XEXP (x, 0))) - + cached_num_sign_bit_copies (XEXP (x, 0), VOIDmode, - known_x, known_mode, known_ret)); + if (is_a (GET_MODE (XEXP (x, 0)), &inner_mode)) + return (bitwidth - GET_MODE_PRECISION (inner_mode) + + cached_num_sign_bit_copies (XEXP (x, 0), inner_mode, + known_x, known_mode, known_ret)); + break; case TRUNCATE: /* For a smaller object, just ignore the high bits. */ - num0 = cached_num_sign_bit_copies (XEXP (x, 0), VOIDmode, + inner_mode = as_a (GET_MODE (XEXP (x, 0))); + num0 = cached_num_sign_bit_copies (XEXP (x, 0), inner_mode, known_x, known_mode, known_ret); - return MAX (1, (num0 - (int) (GET_MODE_PRECISION (GET_MODE (XEXP (x, 0))) + return MAX (1, (num0 - (int) (GET_MODE_PRECISION (inner_mode) - bitwidth))); case NOT: @@ -5200,7 +5201,7 @@ num_sign_bit_copies1 (const_rtx x, machi known_x, known_mode, known_ret); if (CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) > 0 - && INTVAL (XEXP (x, 1)) < GET_MODE_PRECISION (GET_MODE (x))) + && INTVAL (XEXP (x, 1)) < xmode_width) num0 = MIN ((int) bitwidth, num0 + INTVAL (XEXP (x, 1))); return num0; @@ -5210,7 +5211,7 @@ num_sign_bit_copies1 (const_rtx x, machi if (!CONST_INT_P (XEXP (x, 1)) || INTVAL (XEXP (x, 1)) < 0 || INTVAL (XEXP (x, 1)) >= (int) bitwidth - || INTVAL (XEXP (x, 1)) >= GET_MODE_PRECISION (GET_MODE (x))) + || INTVAL (XEXP (x, 1)) >= xmode_width) return 1; num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,