public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] combine: Fix handling of unsigned constants
@ 2023-10-06  7:45 Stefan Schulze Frielinghaus
  2023-10-13 17:06 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Schulze Frielinghaus @ 2023-10-06  7:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: Stefan Schulze Frielinghaus

If a CONST_INT represents an integer of a mode with fewer bits than in
HOST_WIDE_INT, then the integer is sign extended.  For those two
optimizations touched by this patch, the integers of interest have only
the most significant bit set w.r.t their mode, therefore, they were sign
extended.  Thus in order to get the integer of interest, we have to chop
off the high bits.

Bootstrapped and regtested on x64, powerpc64le, and s390.  Ok for
mainline?

gcc/ChangeLog:

	* combine.cc (simplify_compare_const): Fix handling of unsigned
	constants.
---
 gcc/combine.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 468b7fde911..80c4ff0fbaf 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -11923,7 +11923,7 @@ simplify_compare_const (enum rtx_code code, machine_mode mode,
       /* (unsigned) < 0x80000000 is equivalent to >= 0.  */
       else if (is_a <scalar_int_mode> (mode, &int_mode)
 	       && GET_MODE_PRECISION (int_mode) - 1 < HOST_BITS_PER_WIDE_INT
-	       && ((unsigned HOST_WIDE_INT) const_op
+	       && (((unsigned HOST_WIDE_INT) const_op & GET_MODE_MASK (int_mode))
 		   == HOST_WIDE_INT_1U << (GET_MODE_PRECISION (int_mode) - 1)))
 	{
 	  const_op = 0;
@@ -11962,7 +11962,7 @@ simplify_compare_const (enum rtx_code code, machine_mode mode,
       /* (unsigned) >= 0x80000000 is equivalent to < 0.  */
       else if (is_a <scalar_int_mode> (mode, &int_mode)
 	       && GET_MODE_PRECISION (int_mode) - 1 < HOST_BITS_PER_WIDE_INT
-	       && ((unsigned HOST_WIDE_INT) const_op
+	       && (((unsigned HOST_WIDE_INT) const_op & GET_MODE_MASK (int_mode))
 		   == HOST_WIDE_INT_1U << (GET_MODE_PRECISION (int_mode) - 1)))
 	{
 	  const_op = 0;
-- 
2.41.0


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

* Re: [PATCH] combine: Fix handling of unsigned constants
  2023-10-06  7:45 [PATCH] combine: Fix handling of unsigned constants Stefan Schulze Frielinghaus
@ 2023-10-13 17:06 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2023-10-13 17:06 UTC (permalink / raw)
  To: Stefan Schulze Frielinghaus, gcc-patches



On 10/6/23 01:45, Stefan Schulze Frielinghaus wrote:
> If a CONST_INT represents an integer of a mode with fewer bits than in
> HOST_WIDE_INT, then the integer is sign extended.  For those two
> optimizations touched by this patch, the integers of interest have only
> the most significant bit set w.r.t their mode, therefore, they were sign
> extended.  Thus in order to get the integer of interest, we have to chop
> off the high bits.
> 
> Bootstrapped and regtested on x64, powerpc64le, and s390.  Ok for
> mainline?
> 
> gcc/ChangeLog:
> 
> 	* combine.cc (simplify_compare_const): Fix handling of unsigned
> 	constants.
OK
jeff

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

end of thread, other threads:[~2023-10-13 17:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06  7:45 [PATCH] combine: Fix handling of unsigned constants Stefan Schulze Frielinghaus
2023-10-13 17:06 ` 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).