public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1406] Replace a HWI_COMPUTABLE_MODE_P with wide-int in simplify-rtx.cc.
@ 2023-05-30 13:48 Roger Sayle
  0 siblings, 0 replies; only message in thread
From: Roger Sayle @ 2023-05-30 13:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2a941f9f824b64ea8b42c885746fbc5f5321589d

commit r14-1406-g2a941f9f824b64ea8b42c885746fbc5f5321589d
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Tue May 30 14:46:45 2023 +0100

    Replace a HWI_COMPUTABLE_MODE_P with wide-int in simplify-rtx.cc.
    
    This patch enhances one of the optimizations in simplify_binary_operation_1
    to allow it to simplify RTL expressions in modes wider than HOST_WIDE_INT
    by replacing a use of HWI_COMPUTABLE_MODE_P and UINTVAL with wide_int.
    
    The motivating example is a pending x86_64 backend patch that produces
    the following RTL in combine:
    
    (and:TI (zero_extend:TI (reg:DI 89))
            (const_wide_int 0x0ffffffffffffffff))
    
    where the AND is redundant, as the mask, ~0LL, is DImode's MODE_MASK.
    There's already an optimization that catches this for narrower modes,
    transforming (and:HI (zero_extend:HI (reg:QI x)) (const_int 0xff))
    into (zero_extend:HI (reg:QI x)), but this currently only handles
    CONST_INT not CONST_WIDE_INT.  Fixed by upgrading this transformation
    to use wide_int, specifically rtx_mode_t and wi::mask.
    
    2023-05-30  Roger Sayle  <roger@nextmovesoftware.com>
    
    gcc/ChangeLog
            * simplify-rtx.cc (simplify_binary_operation_1) <AND>: Use wide-int
            instead of HWI_COMPUTABLE_MODE_P and UINTVAL in transformation of
            (and (extend X) C) as (zero_extend (and X C)), to also optimize
            modes wider than HOST_WIDE_INT.

Diff:
---
 gcc/simplify-rtx.cc | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index d6444b40802..8b48bd3553e 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -3826,15 +3826,16 @@ simplify_context::simplify_binary_operation_1 (rtx_code code,
 	 there are no nonzero bits of C outside of X's mode.  */
       if ((GET_CODE (op0) == SIGN_EXTEND
 	   || GET_CODE (op0) == ZERO_EXTEND)
-	  && CONST_INT_P (trueop1)
-	  && HWI_COMPUTABLE_MODE_P (mode)
-	  && (~GET_MODE_MASK (GET_MODE (XEXP (op0, 0)))
-	      & UINTVAL (trueop1)) == 0)
+	  && CONST_SCALAR_INT_P (trueop1)
+	  && is_a <scalar_int_mode> (mode, &int_mode)
+	  && is_a <scalar_int_mode> (GET_MODE (XEXP (op0, 0)), &inner_mode)
+	  && (wi::mask (GET_MODE_PRECISION (inner_mode), true,
+			GET_MODE_PRECISION (int_mode))
+	      & rtx_mode_t (trueop1, mode)) == 0)
 	{
 	  machine_mode imode = GET_MODE (XEXP (op0, 0));
-	  tem = simplify_gen_binary (AND, imode, XEXP (op0, 0),
-				     gen_int_mode (INTVAL (trueop1),
-						   imode));
+	  tem = immed_wide_int_const (rtx_mode_t (trueop1, mode), imode);
+	  tem = simplify_gen_binary (AND, imode, XEXP (op0, 0), tem);
 	  return simplify_gen_unary (ZERO_EXTEND, mode, tem, imode);
 	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-30 13:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 13:48 [gcc r14-1406] Replace a HWI_COMPUTABLE_MODE_P with wide-int in simplify-rtx.cc Roger Sayle

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).