]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
combine: Fix handling of unsigned constants
authorStefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Sun, 15 Oct 2023 09:20:01 +0000 (11:20 +0200)
committerStefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Sun, 15 Oct 2023 09:20:01 +0000 (11:20 +0200)
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.

gcc/ChangeLog:

* combine.cc (simplify_compare_const): Fix handling of unsigned
constants.

gcc/combine.cc

index 360aa2f25e6a3167ac215e545d13e5347c18b017..cb48e7f5b97f75cfce2c4d92cbb4ef4a6b7a0038 100644 (file)
@@ -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;