[PATCH] Fix ICE in convert_move expanding V_C_E via store-flag

Richard Guenther rguenther@suse.de
Tue May 19 10:53:00 GMT 2009


On Mon, 18 May 2009, Richard Guenther wrote:

> 
> When expanding the V_C_E of the comparison result in the testcase below
> we end up calling do_store_flag for an integer comparison with
> SFmode target mode.  This isn't going to work and probably was never
> intended to.  The following avoids the situation.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, ok?

Patch was missing a ChangeLog.

Richard.

2009-05-19  Richard Guenther  <rguenther@suse.de>

	* expr.c (expand_expr_real_1): Avoid calling do_store_flag
	with mismatched comparison modes.

	* gcc.c-torture/compile/20090518-1.c: New testcase.

Index: gcc/expr.c
===================================================================
*** gcc/expr.c	(revision 147659)
--- gcc/expr.c	(working copy)
*************** expand_expr_real_1 (tree exp, rtx target
*** 9042,9050 ****
      case LTGT_EXPR:
        temp = do_store_flag (exp,
  			    modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
! 			    tmode != VOIDmode ? tmode : mode);
        if (temp != 0)
! 	return temp;
  
        /* For foo != 0, load foo, and if it is nonzero load 1 instead.  */
        if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
--- 9042,9060 ----
      case LTGT_EXPR:
        temp = do_store_flag (exp,
  			    modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
! 			    (tmode != VOIDmode
! 			     && GET_MODE_CLASS (tmode) == GET_MODE_CLASS (mode))
! 			    ? tmode : mode);
        if (temp != 0)
! 	{
! 	  /* If we have a mode-change that convert_move cannot handle
! 	     we called do_store_flag with the target mode of the comparison.
! 	     Fix that here.  */
! 	  if (tmode != VOIDmode
! 	      && GET_MODE_CLASS (tmode) != GET_MODE_CLASS (mode))
! 	    temp = simplify_gen_subreg (tmode, temp, mode, 0);
! 	  return temp;
! 	}
  
        /* For foo != 0, load foo, and if it is nonzero load 1 instead.  */
        if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
Index: gcc/testsuite/gcc.c-torture/compile/20090518-1.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/20090518-1.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/compile/20090518-1.c	(revision 0)
***************
*** 0 ****
--- 1,6 ----
+ float
+ foo(int i)
+ {
+   int j = i == 42;
+   return *(float *)&j;
+ }



More information about the Gcc-patches mailing list