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] Bug in simplify_if_then_else


Hello,

on Jun 05, 2003, Jan Hubicka committed a patch to perform this
optimization:
        * combine.c (simplify_if_then_else): (IF_THEN_ELSE (NE REG 0) (0) (8))
        is REG for nonzero_bits (REG) == 8.  

Unfortunately, this is invalid if the mode of the IF_THEN_ELSE
is different from the mode of REG; this occurs in the test case
attached below on s390-ibm-linux.

The following patch simply refuses to do the optimization if
the modes do not match (it might be possible to improve upon
this by using subregs, but for now this patch fixes the bug
without introducing new risks ...).

Bootstrapped/regtested on s390-ibm-linux and s390x-ibm-linux
on both 3.4 and CVS head.

OK for 3.4 and head?

Bye,
Ulrich

ChangeLog:

	* combine.c (simplify_if_then_else): Do not replace 
	(if_then_else (ne reg 0) (0) (const_int)) by (reg) if the
	modes differ.

testsuite/ChangeLog:

	* gcc.dg/20040217-1.c: New test.


Index: gcc/combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.400.4.2
diff -c -p -r1.400.4.2 combine.c
*** gcc/combine.c	23 Jan 2004 23:35:54 -0000	1.400.4.2
--- gcc/combine.c	17 Feb 2004 16:52:39 -0000
*************** simplify_if_then_else (rtx x)
*** 4929,4934 ****
--- 4929,4935 ----
    /* (IF_THEN_ELSE (NE REG 0) (0) (8)) is REG for nonzero_bits (REG) == 8.  */
    if (true_code == NE && XEXP (cond, 1) == const0_rtx
        && false_rtx == const0_rtx && GET_CODE (true_rtx) == CONST_INT
+       && GET_MODE (XEXP (cond, 0)) == mode
        && (INTVAL (true_rtx) & GET_MODE_MASK (mode))
  	  == nonzero_bits (XEXP (cond, 0), mode)
        && (i = exact_log2 (INTVAL (true_rtx) & GET_MODE_MASK (mode))) >= 0)
*** /dev/null	Mon Aug 11 14:39:32 2003
--- gcc/testsuite/gcc.dg/20040217-1.c	Tue Feb 17 17:51:08 2004
***************
*** 0 ****
--- 1,19 ----
+ /* This used to ICE on s390x due to a bug in simplify_if_then_else.  */
+ /* { dg-do compile } */
+ /* { dg-options "-O2" } */
+ 
+ extern void use (int);
+ void test (void)
+ {
+   union 
+    {
+      unsigned long ul;
+      signed char sc;
+    } u;
+ 
+   u.sc = 8;
+   u.sc &= 25;
+ 
+   use (u.sc);
+ }
+ 
-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de


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