This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

patch: sign extend constants in simplify_ternary_operation


This patch:

http://gcc.gnu.org/ml/gcc-patches/2004-11/msg00317.html

is now making extract_bit_field to generate valid RTL.  However, in one
particular case, cse is transforming a const_int incorrectly.

CSE transforms my code into:

(insn 26 25 27 0 (set (reg:DI 136)
        (const_int -4611686018427387904 [0xc000000000000000])) 301 {*movdi_internal32} (nil)
    (nil))

(insn 27 26 29 0 (set (reg:SI 137)
        (zero_extract:SI (subreg:SI (reg:DI 136) 0)
            (const_int 32 [0x20])
            (const_int 0 [0x0]))) 108 {extzvsi} (nil)
    (nil))

...and then replacing the zero_extract with:

	(const_int 3221225472 [0xc0000000])

Giving me:

	(insn 27 26 29 0 (set (reg:SI 137)
	        (const_int 3221225472 [0xc0000000])) 283 ....

Notice, the constant is not extended correctly.

This patch fixes the problem.

Bootstrap and tested on powerpc-linux-gnu.

Ok?

	* simplify-rtx.c (simplify_ternary_operation): Use
	trunc_int_for_mode.

Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.207
diff -c -p -r1.207 simplify-rtx.c
*** simplify-rtx.c	28 Oct 2004 12:47:21 -0000	1.207
--- simplify-rtx.c	19 Nov 2004 21:40:38 -0000
*************** simplify_ternary_operation (enum rtx_cod
*** 3170,3176 ****
  		  != ((HOST_WIDE_INT) (-1) << (width - 1))))
  	    val &= ((HOST_WIDE_INT) 1 << width) - 1;
  
! 	  return GEN_INT (val);
  	}
        break;
  
--- 3170,3176 ----
  		  != ((HOST_WIDE_INT) (-1) << (width - 1))))
  	    val &= ((HOST_WIDE_INT) 1 << width) - 1;
  
! 	  return gen_int_mode (val, mode);
  	}
        break;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]