[gcc r17-2900] hwint: Simplify sext_hwi.

Kael Andrew Franco via Gcc-cvs <[email protected]> Mon, 3 Aug 2026 17:25:31 +0000 (GMT)
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:c4c8f794634e08f6fc432c8883ff1ff1e10078f4

commit r17-2900-gc4c8f794634e08f6fc432c8883ff1ff1e10078f4
Author: Kael Andrew Alonzo Franco <[email protected]>
Date:   Mon Aug 3 13:24:53 2026 -0400

    hwint: Simplify sext_hwi.
    
    This combines duplicated C++ code so any C++ compiler compiles this
    header file faster.
    
    Bootstrapped and tested on x86_64-pc-linux-gnu.
    
    gcc/ChangeLog:
    
            * hwint.h (sext_hwi): Combine duplicated C++ code.
    
    Signed-off-by: Kael Andrew Franco <[email protected]>

Diff:
---
 gcc/hwint.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/gcc/hwint.h b/gcc/hwint.h
index dfe646cf9802..454ee0efdcb0 100644
--- a/gcc/hwint.h
+++ b/gcc/hwint.h
@@ -302,27 +302,24 @@ sext_hwi (HOST_WIDE_INT src, unsigned int prec)
   if (prec == HOST_BITS_PER_WIDE_INT)
     return src;
   else
-#if defined (__GNUC__)
     {
+      gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT);
+#if defined (__GNUC__)
       /* Take the faster path if the implementation-defined bits it's relying
 	 on are implemented the way we expect them to be.  Namely, conversion
 	 from unsigned to signed preserves bit pattern, and right shift of
 	 a signed value propagates the sign bit.
 	 We have to convert from signed to unsigned and back, because when left
 	 shifting signed values, any overflow is undefined behavior.  */
-      gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT);
       int shift = HOST_BITS_PER_WIDE_INT - prec;
       return ((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) src << shift)) >> shift;
-    }
 #else
-    {
       /* Fall back to the slower, well defined path otherwise.  */
-      gcc_checking_assert (prec < HOST_BITS_PER_WIDE_INT);
       HOST_WIDE_INT sign_mask = HOST_WIDE_INT_1 << (prec - 1);
       HOST_WIDE_INT value_mask = (HOST_WIDE_INT_1U << prec) - HOST_WIDE_INT_1U;
       return (((src & value_mask) ^ sign_mask) - sign_mask);
-    }
 #endif
+    }
 }
 
 /* Zero extend SRC starting from PREC.  */