[PATCH] Fix combine.c compilation warnings (take 3)

Roger Sayle roger@eyesopen.com
Sat Jul 6 15:28:00 GMT 2002


This patch fixes the remaining 21 compilation warnings in combine.c.
The are all signed/unsigned comparison warnings, that are fixed by
adding the appropriate casts.  In this revised patch I've been
careful to cast "INTVAL"s to "unsigned HOST_WIDE_INT" rather than
accidentally cast down to "unsigned int" as I had in my previous
version.  Many thanks to RTH for catching this.

The following patch has been tested with a complete bootstrap
and "make -k check", all languages except Ada and treelang, on
i686-pc-linux-gnu with no new regressions.

Ok for mainline?


2002-07-06  Roger Sayle  <roger@eyesopen.com>

	* combine.c (combine_simplify_rtx): Add an explicit cast
	to avoid signed/unsigned comparison warning.
	(simplify_if_then_else): Likewise.
	(extended_count): Likewise.
	(simplify_shift_const): Likewise.
	(simplify_comparison): Likewise.


Index: combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.303
diff -c -3 -p -r1.303 combine.c
*** combine.c	3 Jul 2002 21:00:23 -0000	1.303
--- combine.c	6 Jul 2002 03:55:44 -0000
*************** combine_simplify_rtx (x, op0_mode, last,
*** 4104,4110 ****
        if (TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
  				 GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))))
  	  && num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0)))
! 	     >= GET_MODE_BITSIZE (mode) + 1
  	  && ! (GET_CODE (XEXP (x, 0)) == LSHIFTRT
  		&& GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT))
  	return gen_lowpart_for_combine (mode, XEXP (x, 0));
--- 4104,4110 ----
        if (TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
  				 GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))))
  	  && num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0)))
! 	     >= (unsigned int) (GET_MODE_BITSIZE (mode) + 1)
  	  && ! (GET_CODE (XEXP (x, 0)) == LSHIFTRT
  		&& GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT))
  	return gen_lowpart_for_combine (mode, XEXP (x, 0));
*************** simplify_if_then_else (x)
*** 4865,4871 ****
  	       && subreg_lowpart_p (XEXP (XEXP (t, 0), 0))
  	       && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 0)), f)
  	       && (num_sign_bit_copies (f, GET_MODE (f))
! 		   > (GET_MODE_BITSIZE (mode)
  		      - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 0))))))
  	{
  	  c1 = XEXP (XEXP (t, 0), 1); z = f; op = GET_CODE (XEXP (t, 0));
--- 4865,4872 ----
  	       && subreg_lowpart_p (XEXP (XEXP (t, 0), 0))
  	       && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 0)), f)
  	       && (num_sign_bit_copies (f, GET_MODE (f))
! 		   > (unsigned int)
! 		     (GET_MODE_BITSIZE (mode)
  		      - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 0))))))
  	{
  	  c1 = XEXP (XEXP (t, 0), 1); z = f; op = GET_CODE (XEXP (t, 0));
*************** simplify_if_then_else (x)
*** 4880,4886 ****
  	       && subreg_lowpart_p (XEXP (XEXP (t, 0), 1))
  	       && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 1)), f)
  	       && (num_sign_bit_copies (f, GET_MODE (f))
! 		   > (GET_MODE_BITSIZE (mode)
  		      - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 1))))))
  	{
  	  c1 = XEXP (XEXP (t, 0), 0); z = f; op = GET_CODE (XEXP (t, 0));
--- 4881,4888 ----
  	       && subreg_lowpart_p (XEXP (XEXP (t, 0), 1))
  	       && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 1)), f)
  	       && (num_sign_bit_copies (f, GET_MODE (f))
! 		   > (unsigned int)
! 		     (GET_MODE_BITSIZE (mode)
  		      - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 1))))))
  	{
  	  c1 = XEXP (XEXP (t, 0), 0); z = f; op = GET_CODE (XEXP (t, 0));
*************** extended_count (x, mode, unsignedp)
*** 8804,8811 ****

    return (unsignedp
  	  ? (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
! 	     ? (GET_MODE_BITSIZE (mode) - 1
! 		- floor_log2 (nonzero_bits (x, mode)))
  	     : 0)
  	  : num_sign_bit_copies (x, mode) - 1);
  }
--- 8806,8813 ----

    return (unsignedp
  	  ? (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
! 	     ? (unsigned int) (GET_MODE_BITSIZE (mode) - 1
! 			       - floor_log2 (nonzero_bits (x, mode)))
  	     : 0)
  	  : num_sign_bit_copies (x, mode) - 1);
  }
*************** simplify_shift_const (x, code, result_mo
*** 9035,9041 ****
  	 multiple operations, each of which are defined, we know what the
  	 result is supposed to be.  */

!       if (count > GET_MODE_BITSIZE (shift_mode) - 1)
  	{
  	  if (code == ASHIFTRT)
  	    count = GET_MODE_BITSIZE (shift_mode) - 1;
--- 9037,9043 ----
  	 multiple operations, each of which are defined, we know what the
  	 result is supposed to be.  */

!       if (count > (unsigned int) (GET_MODE_BITSIZE (shift_mode) - 1))
  	{
  	  if (code == ASHIFTRT)
  	    count = GET_MODE_BITSIZE (shift_mode) - 1;
*************** simplify_shift_const (x, code, result_mo
*** 9151,9159 ****
  	  if (subreg_lowpart_p (varop)
  	      && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
  		  > GET_MODE_SIZE (GET_MODE (varop)))
! 	      && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
! 		    + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
! 		  == mode_words))
  	    {
  	      varop = SUBREG_REG (varop);
  	      if (GET_MODE_SIZE (GET_MODE (varop)) > GET_MODE_SIZE (mode))
--- 9153,9161 ----
  	  if (subreg_lowpart_p (varop)
  	      && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
  		  > GET_MODE_SIZE (GET_MODE (varop)))
! 	      && (unsigned int) ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
! 				  + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
! 		 == mode_words)
  	    {
  	      varop = SUBREG_REG (varop);
  	      if (GET_MODE_SIZE (GET_MODE (varop)) > GET_MODE_SIZE (mode))
*************** simplify_shift_const (x, code, result_mo
*** 9194,9200 ****
  	     bit of a wider mode may be different from what would be
  	     interpreted as the sign bit in a narrower mode, so, if
  	     the result is narrower, don't discard the shift.  */
! 	  if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
  	      && (GET_MODE_BITSIZE (result_mode)
  		  >= GET_MODE_BITSIZE (GET_MODE (varop))))
  	    {
--- 9196,9203 ----
  	     bit of a wider mode may be different from what would be
  	     interpreted as the sign bit in a narrower mode, so, if
  	     the result is narrower, don't discard the shift.  */
! 	  if (code == LSHIFTRT
! 	      && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
  	      && (GET_MODE_BITSIZE (result_mode)
  		  >= GET_MODE_BITSIZE (GET_MODE (varop))))
  	    {
*************** simplify_shift_const (x, code, result_mo
*** 9228,9235 ****
  		 (ashiftrt:M1 (ashift:M1 (and:M1 (subreg:M1 FOO 0 C2) C3) C1).
  		 This simplifies certain SIGN_EXTEND operations.  */
  	      if (code == ASHIFT && first_code == ASHIFTRT
! 		  && (GET_MODE_BITSIZE (result_mode)
! 		      - GET_MODE_BITSIZE (GET_MODE (varop))) == count)
  		{
  		  /* C3 has the low-order C1 bits zero.  */

--- 9231,9239 ----
  		 (ashiftrt:M1 (ashift:M1 (and:M1 (subreg:M1 FOO 0 C2) C3) C1).
  		 This simplifies certain SIGN_EXTEND operations.  */
  	      if (code == ASHIFT && first_code == ASHIFTRT
! 		  && count == (unsigned int)
! 			      (GET_MODE_BITSIZE (result_mode)
! 			       - GET_MODE_BITSIZE (GET_MODE (varop))))
  		{
  		  /* C3 has the low-order C1 bits zero.  */

*************** simplify_shift_const (x, code, result_mo
*** 9385,9391 ****
  	      && XEXP (XEXP (varop, 0), 1) == constm1_rtx
  	      && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  	      && (code == LSHIFTRT || code == ASHIFTRT)
! 	      && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
  	      && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  	    {
  	      count = 0;
--- 9389,9396 ----
  	      && XEXP (XEXP (varop, 0), 1) == constm1_rtx
  	      && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  	      && (code == LSHIFTRT || code == ASHIFTRT)
! 	      && count == (unsigned int)
! 			  (GET_MODE_BITSIZE (GET_MODE (varop)) - 1)
  	      && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  	    {
  	      count = 0;
*************** simplify_shift_const (x, code, result_mo
*** 9440,9446 ****
  	  if (code == LSHIFTRT
  	      && XEXP (varop, 1) == const0_rtx
  	      && GET_MODE (XEXP (varop, 0)) == result_mode
! 	      && count == GET_MODE_BITSIZE (result_mode) - 1
  	      && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  	      && ((STORE_FLAG_VALUE
  		   & ((HOST_WIDE_INT) 1
--- 9445,9451 ----
  	  if (code == LSHIFTRT
  	      && XEXP (varop, 1) == const0_rtx
  	      && GET_MODE (XEXP (varop, 0)) == result_mode
! 	      && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
  	      && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  	      && ((STORE_FLAG_VALUE
  		   & ((HOST_WIDE_INT) 1
*************** simplify_shift_const (x, code, result_mo
*** 9459,9465 ****
  	case NEG:
  	  /* (lshiftrt (neg A) C) where A is either 0 or 1 and C is one less
  	     than the number of bits in the mode is equivalent to A.  */
! 	  if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
  	      && nonzero_bits (XEXP (varop, 0), result_mode) == 1)
  	    {
  	      varop = XEXP (varop, 0);
--- 9464,9471 ----
  	case NEG:
  	  /* (lshiftrt (neg A) C) where A is either 0 or 1 and C is one less
  	     than the number of bits in the mode is equivalent to A.  */
! 	  if (code == LSHIFTRT
! 	      && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
  	      && nonzero_bits (XEXP (varop, 0), result_mode) == 1)
  	    {
  	      varop = XEXP (varop, 0);
*************** simplify_shift_const (x, code, result_mo
*** 9483,9489 ****
  	  /* (lshiftrt (plus A -1) C) where A is either 0 or 1 and C
  	     is one less than the number of bits in the mode is
  	     equivalent to (xor A 1).  */
! 	  if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
  	      && XEXP (varop, 1) == constm1_rtx
  	      && nonzero_bits (XEXP (varop, 0), result_mode) == 1
  	      && merge_outer_ops (&outer_op, &outer_const, XOR,
--- 9489,9496 ----
  	  /* (lshiftrt (plus A -1) C) where A is either 0 or 1 and C
  	     is one less than the number of bits in the mode is
  	     equivalent to (xor A 1).  */
! 	  if (code == LSHIFTRT
! 	      && count == (unsigned int) (GET_MODE_BITSIZE (result_mode) - 1)
  	      && XEXP (varop, 1) == constm1_rtx
  	      && nonzero_bits (XEXP (varop, 0), result_mode) == 1
  	      && merge_outer_ops (&outer_op, &outer_const, XOR,
*************** simplify_shift_const (x, code, result_mo
*** 9548,9557 ****

  	  if ((STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  	      && GET_CODE (XEXP (varop, 0)) == ASHIFTRT
! 	      && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
  	      && (code == LSHIFTRT || code == ASHIFTRT)
  	      && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
! 	      && INTVAL (XEXP (XEXP (varop, 0), 1)) == count
  	      && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  	    {
  	      count = 0;
--- 9555,9566 ----

  	  if ((STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  	      && GET_CODE (XEXP (varop, 0)) == ASHIFTRT
! 	      && count == (unsigned int)
! 			  (GET_MODE_BITSIZE (GET_MODE (varop)) - 1)
  	      && (code == LSHIFTRT || code == ASHIFTRT)
  	      && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
! 	      && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (varop, 0), 1))
! 		 == count
  	      && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  	    {
  	      count = 0;
*************** simplify_shift_const (x, code, result_mo
*** 9615,9621 ****

    if (x && GET_RTX_CLASS (GET_CODE (x)) == '2'
        && GET_CODE (XEXP (x, 1)) == CONST_INT
!       && INTVAL (XEXP (x, 1)) == count)
      const_rtx = XEXP (x, 1);
    else
      const_rtx = GEN_INT (count);
--- 9624,9630 ----

    if (x && GET_RTX_CLASS (GET_CODE (x)) == '2'
        && GET_CODE (XEXP (x, 1)) == CONST_INT
!       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) == count)
      const_rtx = XEXP (x, 1);
    else
      const_rtx = GEN_INT (count);
*************** simplify_comparison (code, pop0, pop1)
*** 10527,10533 ****
  			& ~GET_MODE_MASK (mode))
  		  || (num_sign_bit_copies (XEXP (SUBREG_REG (op0), 0),
  					   GET_MODE (SUBREG_REG (op0)))
! 		      > (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
  			 - GET_MODE_BITSIZE (mode)))))
  	    {
  	      op0 = SUBREG_REG (op0);
--- 10536,10543 ----
  			& ~GET_MODE_MASK (mode))
  		  || (num_sign_bit_copies (XEXP (SUBREG_REG (op0), 0),
  					   GET_MODE (SUBREG_REG (op0)))
! 		      > (unsigned int)
! 			(GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
  			 - GET_MODE_BITSIZE (mode)))))
  	    {
  	      op0 = SUBREG_REG (op0);
*************** simplify_comparison (code, pop0, pop1)
*** 10611,10617 ****
  	     of bits in X minus 1, is one iff X > 0.  */
  	  if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == ASHIFTRT
  	      && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
! 	      && INTVAL (XEXP (XEXP (op0, 0), 1)) == mode_width - 1
  	      && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)))
  	    {
  	      op0 = XEXP (op0, 1);
--- 10621,10628 ----
  	     of bits in X minus 1, is one iff X > 0.  */
  	  if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == ASHIFTRT
  	      && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
! 	      && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (op0, 0), 1))
! 		 == mode_width - 1
  	      && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)))
  	    {
  	      op0 = XEXP (op0, 1);
*************** simplify_comparison (code, pop0, pop1)
*** 10869,10875 ****
  	     low-order bit.  */
  	  if (const_op == 0 && equality_comparison_p
  	      && GET_CODE (XEXP (op0, 1)) == CONST_INT
! 	      && INTVAL (XEXP (op0, 1)) == mode_width - 1)
  	    {
  	      op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  					    (HOST_WIDE_INT) 1);
--- 10880,10887 ----
  	     low-order bit.  */
  	  if (const_op == 0 && equality_comparison_p
  	      && GET_CODE (XEXP (op0, 1)) == CONST_INT
! 	      && (unsigned HOST_WIDE_INT) INTVAL (XEXP (op0, 1))
! 		 == mode_width - 1)
  	    {
  	      op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  					    (HOST_WIDE_INT) 1);
*************** simplify_comparison (code, pop0, pop1)
*** 10966,10972 ****
  	  if (const_op == 0
  	      && (equality_comparison_p || sign_bit_comparison_p)
  	      && GET_CODE (XEXP (op0, 1)) == CONST_INT
! 	      && INTVAL (XEXP (op0, 1)) == mode_width - 1)
  	    {
  	      op0 = XEXP (op0, 0);
  	      code = (code == NE || code == GT ? LT : GE);
--- 10978,10985 ----
  	  if (const_op == 0
  	      && (equality_comparison_p || sign_bit_comparison_p)
  	      && GET_CODE (XEXP (op0, 1)) == CONST_INT
! 	      && (unsigned HOST_WIDE_INT) INTVAL (XEXP (op0, 1))
! 		 == mode_width - 1)
  	    {
  	      op0 = XEXP (op0, 0);
  	      code = (code == NE || code == GT ? LT : GE);
*************** simplify_comparison (code, pop0, pop1)
*** 11067,11075 ****

  	  if (zero_extended
  	      || ((num_sign_bit_copies (op0, tmode)
! 		   > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))
  		  && (num_sign_bit_copies (op1, tmode)
! 		      > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))))
  	    {
  	      /* If OP0 is an AND and we don't have an AND in MODE either,
  		 make a new AND in the proper mode.  */
--- 11080,11090 ----

  	  if (zero_extended
  	      || ((num_sign_bit_copies (op0, tmode)
! 		   > (unsigned int) (GET_MODE_BITSIZE (tmode)
! 				     - GET_MODE_BITSIZE (mode)))
  		  && (num_sign_bit_copies (op1, tmode)
! 		      > (unsigned int) (GET_MODE_BITSIZE (tmode)
! 					- GET_MODE_BITSIZE (mode)))))
  	    {
  	      /* If OP0 is an AND and we don't have an AND in MODE either,
  		 make a new AND in the proper mode.  */

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



More information about the Gcc-patches mailing list