public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] simplify-rtx: Simplify sign_extend of lshiftrt to zero_extend (PR68330)
@ 2015-11-15  2:15 Segher Boessenkool
  2015-11-16  9:34 ` Eric Botcazou
  0 siblings, 1 reply; 2+ messages in thread
From: Segher Boessenkool @ 2015-11-15  2:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: Segher Boessenkool

Since r230164, in PR68330 combine ends up with a sign_extend of an
lshiftrt by some constant, and it does not know to morph that into a
zero_extract (the extend will always extend with zeroes).  I think
it is best to let simplify-rtx always replace such a sign_extend by
a zero_extend, after which everything works as expected.

Bootstrapped and tested on powerpc64-linux.  Is this okay for trunk?


Segher


2015-11-15  Segher Boessenkool  <segher@kernel.crashing.org>

	PR rtl-optimization/68330
	* simplify-rtx.c (simplify_unary_operation_1): Simplify SIGN_EXTEND
	of LSHIFTRT by a non-zero constant integer.

---
 gcc/simplify-rtx.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index c4fc42a..413d61b 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -1462,6 +1462,13 @@ simplify_unary_operation_1 (enum rtx_code code, machine_mode mode, rtx op)
 	    }
 	}
 
+      /* (sign_extend:M (lshiftrt:N <X> (const_int I))) is better as
+         (zero_extend:M (lshiftrt:N <X> (const_int I))) if I is not 0.  */
+      if (GET_CODE (op) == LSHIFTRT
+	  && CONST_INT_P (XEXP (op, 1))
+	  && XEXP (op, 1) != const0_rtx)
+	return simplify_gen_unary (ZERO_EXTEND, mode, op, GET_MODE (op));
+
 #if defined(POINTERS_EXTEND_UNSIGNED)
       /* As we do not know which address space the pointer is referring to,
 	 we can do this only if the target does not support different pointer
-- 
1.9.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] simplify-rtx: Simplify sign_extend of lshiftrt to zero_extend (PR68330)
  2015-11-15  2:15 [PATCH] simplify-rtx: Simplify sign_extend of lshiftrt to zero_extend (PR68330) Segher Boessenkool
@ 2015-11-16  9:34 ` Eric Botcazou
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2015-11-16  9:34 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-patches

> Since r230164, in PR68330 combine ends up with a sign_extend of an
> lshiftrt by some constant, and it does not know to morph that into a
> zero_extract (the extend will always extend with zeroes).  I think
> it is best to let simplify-rtx always replace such a sign_extend by
> a zero_extend, after which everything works as expected.

Agreed.

> 2015-11-15  Segher Boessenkool  <segher@kernel.crashing.org>
> 
> 	PR rtl-optimization/68330
> 	* simplify-rtx.c (simplify_unary_operation_1): Simplify SIGN_EXTEND
> 	of LSHIFTRT by a non-zero constant integer.

OK, thanks.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-16  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-15  2:15 [PATCH] simplify-rtx: Simplify sign_extend of lshiftrt to zero_extend (PR68330) Segher Boessenkool
2015-11-16  9:34 ` Eric Botcazou

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