From patchwork Wed Aug 23 10:57: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: 804949 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-460790-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SN/z+aBW"; 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 3xcktJ3LPdz9s83 for ; Wed, 23 Aug 2017 20:58:13 +1000 (AEST) 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=ARF0xjYyqfSQUA/LFeiMLKIyvDtaIFnCd2qZ8QeI8nXB/+HYHFy5p mcuM3FBBkKyAsd4DSFb5V9swqsh5JdUCYKU/Bu7ukP1pT0Rryy5wbahrI2pVqgm7 4Okxc+mSQzrzqj4i1oFs0XvbPdrBNIRtJDrYzrZdVs+ayoYj1E5aAo= 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=d31xaS0O5oITX3LDJkGgFJ39/28=; b=SN/z+aBWWQ5eIJ4bCuMe V+u2NNTdByJCdE+1uOuW0jEMlDbEkupJx8TsVaSoVeTa4r6UUW2ePk8gPMAVHAzL 4gCcqpPAIc0AiSaT9vi/knlMprHSVz2+2jGKBwTApCN0j6s8/GSRJNU1MQfg00fO k/T2d1pycdz+5pKirKNDtDg= Received: (qmail 125851 invoked by alias); 23 Aug 2017 10:58:06 -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 125821 invoked by uid 89); 23 Aug 2017 10:58:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f41.google.com Received: from mail-wm0-f41.google.com (HELO mail-wm0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Aug 2017 10:58:03 +0000 Received: by mail-wm0-f41.google.com with SMTP id a70so692957wmd.1 for ; Wed, 23 Aug 2017 03:58:03 -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:date:message-id :user-agent:mime-version; bh=/OZzEjHbdgP7aT8f3arzoPk6M/iYJryMDSc0cH8Z8rI=; b=tD2yIxdH5Qxplppz2wbuFiqiFqZbBIeBp4kHdgNrmcUtR6aeZRuEY/1/aqNhKHi1YB eVUaHqtKizJHj70BNC5ZwAE4ImsgBpaZ022aTOypR+bJp1NzQsV4ZVeIsTMMZp/OWjMK 7VeRGSMH7sPp4LC/i77N/Uz4H0ArYpT4p/mx1upkK33BxOZ/gI/UnPLi3zTiPOlqSK7T 6rL4WixAN8u5ROgGh6IdU6PTeXiBh8GB3I6lQsRPtmDX8aYh772SLH5nv5Z5DdRPZqp9 o9BTFO6JNpc9iqUsmb54LojzoVbC6hMZ32wiX14VPgErV4Gd9OgcCTktfAH8xlcZvJa1 3lVw== X-Gm-Message-State: AHYfb5hxmAjO2Gs9R3KMaoGwbJYwG6gleRLYYCoD1KE9fJO0uy3fuTSC XbGk0ZApvZynELM8HtZ+eg== X-Received: by 10.28.67.68 with SMTP id q65mr1542531wma.162.1503485880877; Wed, 23 Aug 2017 03:58:00 -0700 (PDT) Received: from localhost (92.40.249.210.threembb.co.uk. [92.40.249.210]) by smtp.gmail.com with ESMTPSA id h190sm1608232wmd.4.2017.08.23.03.57.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2017 03:57:59 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Make more use of GET_MODE_UNIT_PRECISION Date: Wed, 23 Aug 2017 11:57:57 +0100 Message-ID: <87fucitutm.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch is like the earlier GET_MODE_UNIT_SIZE one, but for precisions rather than sizes. There is one behavioural change in expand_debug_expr: we shouldn't use lowpart subregs for non-scalar truncations, since that would just reinterpret some of the scalars and drop the rest. (This probably doesn't trigger in practice.) Using TRUNCATE is fine for scalars, since simplify_gen_unary knows when a subreg can be used. Tested on aarch64-linux-gnu and x86_64-linux-gnu, and by making sure that there were no differences in testsuite assembly output for one target per CPU. OK to install? Richard 2017-08-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * cfgexpand.c (expand_debug_expr): Use GET_MODE_UNIT_PRECISION. (expand_debug_source_expr): Likewise. * combine.c (combine_simplify_rtx): Likewise. * cse.c (fold_rtx): Likewise. * optabs.c (expand_float): Likewise. * simplify-rtx.c (simplify_unary_operation_1): Likewise. (simplify_binary_operation_1): Likewise. Index: gcc/cfgexpand.c =================================================================== --- gcc/cfgexpand.c 2017-08-23 10:48:32.452867722 +0100 +++ gcc/cfgexpand.c 2017-08-23 10:49:04.239202074 +0100 @@ -4355,9 +4355,12 @@ expand_debug_expr (tree exp) else op0 = simplify_gen_unary (FIX, mode, op0, inner_mode); } - else if (CONSTANT_P (op0) - || GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (inner_mode)) + else if (GET_MODE_UNIT_PRECISION (mode) + == GET_MODE_UNIT_PRECISION (inner_mode)) op0 = lowpart_subreg (mode, op0, inner_mode); + else if (GET_MODE_UNIT_PRECISION (mode) + < GET_MODE_UNIT_PRECISION (inner_mode)) + op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode); else if (UNARY_CLASS_P (exp) ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) : unsignedp) @@ -5214,9 +5217,12 @@ expand_debug_source_expr (tree exp) else op0 = simplify_gen_unary (FIX, mode, op0, inner_mode); } - else if (CONSTANT_P (op0) - || GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (inner_mode)) + else if (GET_MODE_UNIT_PRECISION (mode) + == GET_MODE_UNIT_PRECISION (inner_mode)) op0 = lowpart_subreg (mode, op0, inner_mode); + else if (GET_MODE_UNIT_PRECISION (mode) + < GET_MODE_UNIT_PRECISION (inner_mode)) + op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode); else if (TYPE_UNSIGNED (TREE_TYPE (exp))) op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode); else Index: gcc/combine.c =================================================================== --- gcc/combine.c 2017-08-23 10:48:32.453862693 +0100 +++ gcc/combine.c 2017-08-23 10:49:04.240219975 +0100 @@ -5825,7 +5825,7 @@ combine_simplify_rtx (rtx x, machine_mod if (GET_CODE (temp) == ASHIFTRT && CONST_INT_P (XEXP (temp, 1)) - && INTVAL (XEXP (temp, 1)) == GET_MODE_PRECISION (mode) - 1) + && INTVAL (XEXP (temp, 1)) == GET_MODE_UNIT_PRECISION (mode) - 1) return simplify_shift_const (NULL_RTX, LSHIFTRT, mode, XEXP (temp, 0), INTVAL (XEXP (temp, 1))); Index: gcc/cse.c =================================================================== --- gcc/cse.c 2017-08-23 10:48:32.454857664 +0100 +++ gcc/cse.c 2017-08-23 10:49:04.241237877 +0100 @@ -3606,7 +3606,7 @@ fold_rtx (rtx x, rtx_insn *insn) enum rtx_code associate_code; if (is_shift - && (INTVAL (const_arg1) >= GET_MODE_PRECISION (mode) + && (INTVAL (const_arg1) >= GET_MODE_UNIT_PRECISION (mode) || INTVAL (const_arg1) < 0)) { if (SHIFT_COUNT_TRUNCATED) @@ -3655,7 +3655,7 @@ fold_rtx (rtx x, rtx_insn *insn) break; if (is_shift - && (INTVAL (inner_const) >= GET_MODE_PRECISION (mode) + && (INTVAL (inner_const) >= GET_MODE_UNIT_PRECISION (mode) || INTVAL (inner_const) < 0)) { if (SHIFT_COUNT_TRUNCATED) @@ -3686,7 +3686,7 @@ fold_rtx (rtx x, rtx_insn *insn) if (is_shift && CONST_INT_P (new_const) - && INTVAL (new_const) >= GET_MODE_PRECISION (mode)) + && INTVAL (new_const) >= GET_MODE_UNIT_PRECISION (mode)) { /* As an exception, we can turn an ASHIFTRT of this form into a shift of the number of bits - 1. */ Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2017-08-23 10:47:48.126586565 +0100 +++ gcc/optabs.c 2017-08-23 10:49:04.242255779 +0100 @@ -4658,7 +4658,8 @@ expand_float (rtx to, rtx from, int unsi int doing_unsigned = unsignedp; if (fmode != GET_MODE (to) - && significand_size (fmode) < GET_MODE_PRECISION (GET_MODE (from))) + && (significand_size (fmode) + < GET_MODE_UNIT_PRECISION (GET_MODE (from)))) continue; icode = can_float_p (fmode, imode, unsignedp); Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2017-08-23 10:47:48.127582392 +0100 +++ gcc/simplify-rtx.c 2017-08-23 10:49:04.242255779 +0100 @@ -1130,7 +1130,7 @@ simplify_unary_operation_1 (enum rtx_cod C is equal to the width of MODE minus 1. */ if (GET_CODE (op) == ASHIFTRT && CONST_INT_P (XEXP (op, 1)) - && INTVAL (XEXP (op, 1)) == GET_MODE_PRECISION (mode) - 1) + && INTVAL (XEXP (op, 1)) == GET_MODE_UNIT_PRECISION (mode) - 1) return simplify_gen_binary (LSHIFTRT, mode, XEXP (op, 0), XEXP (op, 1)); @@ -1138,7 +1138,7 @@ simplify_unary_operation_1 (enum rtx_cod C is equal to the width of MODE minus 1. */ if (GET_CODE (op) == LSHIFTRT && CONST_INT_P (XEXP (op, 1)) - && INTVAL (XEXP (op, 1)) == GET_MODE_PRECISION (mode) - 1) + && INTVAL (XEXP (op, 1)) == GET_MODE_UNIT_PRECISION (mode) - 1) return simplify_gen_binary (ASHIFTRT, mode, XEXP (op, 0), XEXP (op, 1)); @@ -1438,19 +1438,21 @@ simplify_unary_operation_1 (enum rtx_cod if (lcode == ASHIFTRT) /* Number of bits not shifted off the end. */ - bits = GET_MODE_PRECISION (lmode) - INTVAL (XEXP (lhs, 1)); + bits = (GET_MODE_UNIT_PRECISION (lmode) + - INTVAL (XEXP (lhs, 1))); else /* lcode == SIGN_EXTEND */ /* Size of inner mode. */ - bits = GET_MODE_PRECISION (GET_MODE (XEXP (lhs, 0))); + bits = GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (lhs, 0))); if (rcode == ASHIFTRT) - bits += GET_MODE_PRECISION (rmode) - INTVAL (XEXP (rhs, 1)); + bits += (GET_MODE_UNIT_PRECISION (rmode) + - INTVAL (XEXP (rhs, 1))); else /* rcode == SIGN_EXTEND */ - bits += GET_MODE_PRECISION (GET_MODE (XEXP (rhs, 0))); + bits += GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (rhs, 0))); /* We can only widen multiplies if the result is mathematiclly equivalent. I.e. if overflow was impossible. */ - if (bits <= GET_MODE_PRECISION (GET_MODE (op))) + if (bits <= GET_MODE_UNIT_PRECISION (GET_MODE (op))) return simplify_gen_binary (MULT, mode, simplify_gen_unary (SIGN_EXTEND, mode, lhs, lmode), @@ -1475,8 +1477,8 @@ simplify_unary_operation_1 (enum rtx_cod (sign_extend:M (zero_extend:N )) is (zero_extend:M ). */ if (GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND) { - gcc_assert (GET_MODE_PRECISION (mode) - > GET_MODE_PRECISION (GET_MODE (op))); + gcc_assert (GET_MODE_UNIT_PRECISION (mode) + > GET_MODE_UNIT_PRECISION (GET_MODE (op))); return simplify_gen_unary (GET_CODE (op), mode, XEXP (op, 0), GET_MODE (XEXP (op, 0))); } @@ -1575,19 +1577,21 @@ simplify_unary_operation_1 (enum rtx_cod if (lcode == LSHIFTRT) /* Number of bits not shifted off the end. */ - bits = GET_MODE_PRECISION (lmode) - INTVAL (XEXP (lhs, 1)); + bits = (GET_MODE_UNIT_PRECISION (lmode) + - INTVAL (XEXP (lhs, 1))); else /* lcode == ZERO_EXTEND */ /* Size of inner mode. */ - bits = GET_MODE_PRECISION (GET_MODE (XEXP (lhs, 0))); + bits = GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (lhs, 0))); if (rcode == LSHIFTRT) - bits += GET_MODE_PRECISION (rmode) - INTVAL (XEXP (rhs, 1)); + bits += (GET_MODE_UNIT_PRECISION (rmode) + - INTVAL (XEXP (rhs, 1))); else /* rcode == ZERO_EXTEND */ - bits += GET_MODE_PRECISION (GET_MODE (XEXP (rhs, 0))); + bits += GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (rhs, 0))); /* We can only widen multiplies if the result is mathematiclly equivalent. I.e. if overflow was impossible. */ - if (bits <= GET_MODE_PRECISION (GET_MODE (op))) + if (bits <= GET_MODE_UNIT_PRECISION (GET_MODE (op))) return simplify_gen_binary (MULT, mode, simplify_gen_unary (ZERO_EXTEND, mode, lhs, lmode), @@ -2133,7 +2137,6 @@ simplify_binary_operation_1 (enum rtx_co { rtx tem, reversed, opleft, opright; HOST_WIDE_INT val; - unsigned int width = GET_MODE_PRECISION (mode); /* Even if we can't compute a constant result, there are some cases worth simplifying. */ @@ -2698,7 +2701,7 @@ simplify_binary_operation_1 (enum rtx_co && CONST_INT_P (XEXP (opleft, 1)) && CONST_INT_P (XEXP (opright, 1)) && (INTVAL (XEXP (opleft, 1)) + INTVAL (XEXP (opright, 1)) - == GET_MODE_PRECISION (mode))) + == GET_MODE_UNIT_PRECISION (mode))) return gen_rtx_ROTATE (mode, XEXP (opright, 0), XEXP (opleft, 1)); /* Same, but for ashift that has been "simplified" to a wider mode @@ -3337,11 +3340,12 @@ simplify_binary_operation_1 (enum rtx_co #if defined(HAVE_rotate) && defined(HAVE_rotatert) if (CONST_INT_P (trueop1) && IN_RANGE (INTVAL (trueop1), - GET_MODE_PRECISION (mode) / 2 + (code == ROTATE), - GET_MODE_PRECISION (mode) - 1)) + GET_MODE_UNIT_PRECISION (mode) / 2 + (code == ROTATE), + GET_MODE_UNIT_PRECISION (mode) - 1)) return simplify_gen_binary (code == ROTATE ? ROTATERT : ROTATE, - mode, op0, GEN_INT (GET_MODE_PRECISION (mode) - - INTVAL (trueop1))); + mode, op0, + GEN_INT (GET_MODE_UNIT_PRECISION (mode) + - INTVAL (trueop1))); #endif /* FALLTHRU */ case ASHIFTRT: @@ -3395,7 +3399,7 @@ simplify_binary_operation_1 (enum rtx_co if (SHIFT_COUNT_TRUNCATED && CONST_INT_P (op1)) { - val = INTVAL (op1) & (GET_MODE_PRECISION (mode) - 1); + val = INTVAL (op1) & (GET_MODE_UNIT_PRECISION (mode) - 1); if (val != INTVAL (op1)) return simplify_gen_binary (code, mode, op0, GEN_INT (val)); } @@ -3419,7 +3423,7 @@ simplify_binary_operation_1 (enum rtx_co if (GET_CODE (op0) == CLZ && CONST_INT_P (trueop1) && STORE_FLAG_VALUE == 1 - && INTVAL (trueop1) < (HOST_WIDE_INT)width) + && INTVAL (trueop1) < GET_MODE_UNIT_PRECISION (mode)) { machine_mode imode = GET_MODE (XEXP (op0, 0)); unsigned HOST_WIDE_INT zero_val = 0;