From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19394 invoked by alias); 18 Sep 2019 06:56:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 19386 invoked by uid 89); 18 Sep 2019 06:56:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Sep 2019 06:56:24 +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 BD52B1000 for ; Tue, 17 Sep 2019 23:56:22 -0700 (PDT) Received: from localhost (unknown [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 92AA23F59C for ; Tue, 17 Sep 2019 23:58:53 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Extend neg_const_int simplifications to other const rtxes Date: Wed, 18 Sep 2019 06:56:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg01050.txt.bz2 This patch generalises some neg_const_int-based rtx simplifications so that they handle all CONST_SCALAR_INTs and also CONST_POLY_INT. This actually simplifies things a bit, since we no longer have to treat HOST_WIDE_INT_MIN specially. This is tested by later SVE patches. Tested on aarch64-linux-gnu with SVE (with and without follow-on patches) and x86_64-linux-gnu. OK to install? Richard 2019-09-18 Richard Sandiford gcc/ * simplify-rtx.c (neg_const_int): Replace with... (neg_poly_int_rtx): ...this new function. (simplify_binary_operation_1): Extend (minus x C) -> (plus X -C) to all CONST_SCALAR_INTs and to CONST_POLY_INT. (simplify_plus_minus): Likewise for constant terms here. Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2019-07-29 09:41:49.905199370 +0100 +++ gcc/simplify-rtx.c 2019-09-18 07:55:12.829765707 +0100 @@ -46,7 +46,6 @@ Software Foundation; either version 3, o #define HWI_SIGN_EXTEND(low) \ ((((HOST_WIDE_INT) low) < 0) ? HOST_WIDE_INT_M1 : HOST_WIDE_INT_0) -static rtx neg_const_int (machine_mode, const_rtx); static bool plus_minus_operand_p (const_rtx); static rtx simplify_plus_minus (enum rtx_code, machine_mode, rtx, rtx); static rtx simplify_associative_operation (enum rtx_code, machine_mode, @@ -57,17 +56,12 @@ static rtx simplify_unary_operation_1 (e static rtx simplify_binary_operation_1 (enum rtx_code, machine_mode, rtx, rtx, rtx, rtx); -/* Negate a CONST_INT rtx. */ +/* Negate I, which satisfies poly_int_rtx_p. MODE is the mode of I. */ + static rtx -neg_const_int (machine_mode mode, const_rtx i) +neg_poly_int_rtx (machine_mode mode, const_rtx i) { - unsigned HOST_WIDE_INT val = -UINTVAL (i); - - if (!HWI_COMPUTABLE_MODE_P (mode) - && val == UINTVAL (i)) - return simplify_const_unary_operation (NEG, mode, CONST_CAST_RTX (i), - mode); - return gen_int_mode (val, mode); + return immed_wide_int_const (-wi::to_poly_wide (i, mode), mode); } /* Test whether expression, X, is an immediate constant that represents @@ -2547,10 +2541,10 @@ simplify_binary_operation_1 (enum rtx_co return plus_constant (mode, op0, trunc_int_for_mode (-offset, mode)); /* Don't let a relocatable value get a negative coeff. */ - if (CONST_INT_P (op1) && GET_MODE (op0) != VOIDmode) + if (poly_int_rtx_p (op1) && GET_MODE (op0) != VOIDmode) return simplify_gen_binary (PLUS, mode, op0, - neg_const_int (mode, op1)); + neg_poly_int_rtx (mode, op1)); /* (x - (x & y)) -> (x & ~y) */ if (INTEGRAL_MODE_P (mode) && GET_CODE (op1) == AND) @@ -4619,11 +4613,12 @@ simplify_plus_minus (enum rtx_code code, } break; - case CONST_INT: + CASE_CONST_SCALAR_INT: + case CONST_POLY_INT: n_constants++; if (this_neg) { - ops[i].op = neg_const_int (mode, this_op); + ops[i].op = neg_poly_int_rtx (mode, this_op); ops[i].neg = 0; changed = 1; canonicalized = 1; @@ -4748,8 +4743,8 @@ simplify_plus_minus (enum rtx_code code, lneg &= rneg; if (GET_CODE (tem) == NEG) tem = XEXP (tem, 0), lneg = !lneg; - if (CONST_INT_P (tem) && lneg) - tem = neg_const_int (mode, tem), lneg = 0; + if (poly_int_rtx_p (tem) && lneg) + tem = neg_poly_int_rtx (mode, tem), lneg = 0; ops[i].op = tem; ops[i].neg = lneg; @@ -4808,12 +4803,12 @@ simplify_plus_minus (enum rtx_code code, in the array and that any other constant will be next-to-last. */ if (n_ops > 1 - && CONST_INT_P (ops[n_ops - 1].op) + && poly_int_rtx_p (ops[n_ops - 1].op) && CONSTANT_P (ops[n_ops - 2].op)) { rtx value = ops[n_ops - 1].op; if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg) - value = neg_const_int (mode, value); + value = neg_poly_int_rtx (mode, value); if (CONST_INT_P (value)) { ops[n_ops - 2].op = plus_constant (mode, ops[n_ops - 2].op,