* Extend neg_const_int simplifications to other const rtxes
@ 2019-09-18 6:56 Richard Sandiford
2019-09-20 20:25 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2019-09-18 6:56 UTC (permalink / raw)
To: gcc-patches
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 <richard.sandiford@arm.com>
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);
\f
-/* 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,
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Extend neg_const_int simplifications to other const rtxes
2019-09-18 6:56 Extend neg_const_int simplifications to other const rtxes Richard Sandiford
@ 2019-09-20 20:25 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2019-09-20 20:25 UTC (permalink / raw)
To: gcc-patches, richard.sandiford
On 9/18/19 12:56 AM, Richard Sandiford wrote:
> 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 <richard.sandiford@arm.com>
>
> 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.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-09-20 20:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-18 6:56 Extend neg_const_int simplifications to other const rtxes Richard Sandiford
2019-09-20 20:25 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).