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] Fix PR43438


This fixes PR43438 where combine manages to drop a required 
zero-extension.  It is make_extraction that upon simplification to
a CONST_INT fails to zero-/sign-extend its value before returning
it.  I also fail to see how it handles pos == BITS_PER_WORD.

Is there more proper RTL infrastructure to do this zero-/sign-extension
available?  I couldn't find anything not operating on modes.

Thanks,
Richard.

2010-03-19  Richard Guenther  <rguenther@suse.de>

	PR rtl-optimization/43438
	* combine.c (make_extraction): Properly zero-/sign-extend an
	extraction of the low part of a CONST_INT.

	* gcc.c-torture/execute/pr43438.c: New testcase.

Index: gcc/combine.c
===================================================================
*** gcc/combine.c	(revision 157561)
--- gcc/combine.c	(working copy)
*************** make_extraction (enum machine_mode mode,
*** 6793,6800 ****
        if (mode == tmode)
  	return new_rtx;
  
!       if (CONST_INT_P (new_rtx))
! 	return gen_int_mode (INTVAL (new_rtx), mode);
  
        /* If we know that no extraneous bits are set, and that the high
  	 bit is not set, convert the extraction to the cheaper of
--- 6793,6808 ----
        if (mode == tmode)
  	return new_rtx;
  
!       if (CONST_INT_P (new_rtx)
! 	  && pos == 0)
! 	{
! 	  double_int res;
! 	  if (unsignedp)
! 	    res = double_int_zext (shwi_to_double_int (INTVAL (new_rtx)), len);
! 	  else
! 	    res = double_int_sext (shwi_to_double_int (INTVAL (new_rtx)), len);
! 	  return gen_int_mode (res.low, mode);
! 	}
  
        /* If we know that no extraneous bits are set, and that the high
  	 bit is not set, convert the extraction to the cheaper of
Index: gcc/testsuite/gcc.c-torture/execute/pr43438.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr43438.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr43438.c	(revision 0)
***************
*** 0 ****
--- 1,23 ----
+ extern void abort (void);
+ 
+ static unsigned char g_2 = 1;
+ static int g_9;
+ static int *l_8 = &g_9;
+ 
+ static void func_12(int p_13)
+ {
+   int * l_17 = &g_9;
+   *l_17 &= 0 < p_13;
+ }
+ 
+ int main(void)
+ {
+   unsigned char l_11 = 254;
+   *l_8 |= g_2;
+   l_11 |= *l_8;
+   func_12(l_11);
+   if (g_9 != 1)
+     abort ();
+   return 0;
+ } 
+ 


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