public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PRs 33693, 33695 and 33697
@ 2007-10-08 15:22 Richard Guenther
  2007-10-08 16:43 ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Guenther @ 2007-10-08 15:22 UTC (permalink / raw)
  To: gcc-patches


More fold-const.c fallout wrt enabled type checking.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to mainline.

Richard.

2007-10-08  Richard Guenther  <rguenther@suse.de>

	PR middle-end/33693
	PR middle-end/33695
	PR middle-end/33697
	* fold-const.c (fold_binary): Use correct types in folding
	of a * (1 << b) to (a << b).  Likewise for ~A & ~B to ~(A | B)
	and building of RROTATE_EXPR.

	* gcc.dg/pr33693.c: New testcase.
	* gcc.dg/pr33695.c: Likewise.
	* gcc.dg/pr33697.c: Likewise.

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 129036)
--- fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 10344,10359 ****
  	      && (tem = negate_expr (arg1)) != arg1
  	      && !TREE_OVERFLOW (tem))
  	    return fold_build2 (MULT_EXPR, type,
! 	    			negate_expr (arg0), tem);
  
  	  /* (a * (1 << b)) is (a << b)  */
  	  if (TREE_CODE (arg1) == LSHIFT_EXPR
  	      && integer_onep (TREE_OPERAND (arg1, 0)))
! 	    return fold_build2 (LSHIFT_EXPR, type, arg0,
  				TREE_OPERAND (arg1, 1));
  	  if (TREE_CODE (arg0) == LSHIFT_EXPR
  	      && integer_onep (TREE_OPERAND (arg0, 0)))
! 	    return fold_build2 (LSHIFT_EXPR, type, arg1,
  				TREE_OPERAND (arg0, 1));
  
  	  strict_overflow_p = false;
--- 10344,10359 ----
  	      && (tem = negate_expr (arg1)) != arg1
  	      && !TREE_OVERFLOW (tem))
  	    return fold_build2 (MULT_EXPR, type,
! 	    			fold_convert (type, negate_expr (arg0)), tem);
  
  	  /* (a * (1 << b)) is (a << b)  */
  	  if (TREE_CODE (arg1) == LSHIFT_EXPR
  	      && integer_onep (TREE_OPERAND (arg1, 0)))
! 	    return fold_build2 (LSHIFT_EXPR, type, op0,
  				TREE_OPERAND (arg1, 1));
  	  if (TREE_CODE (arg0) == LSHIFT_EXPR
  	      && integer_onep (TREE_OPERAND (arg0, 0)))
! 	    return fold_build2 (LSHIFT_EXPR, type, op1,
  				TREE_OPERAND (arg0, 1));
  
  	  strict_overflow_p = false;
*************** fold_binary (enum tree_code code, tree t
*** 11003,11010 ****
  	{
  	  return fold_build1 (BIT_NOT_EXPR, type,
  			      build2 (BIT_IOR_EXPR, type,
! 				      TREE_OPERAND (arg0, 0),
! 				      TREE_OPERAND (arg1, 0)));
  	}
  
        /* If arg0 is derived from the address of an object or function, we may
--- 11003,11012 ----
  	{
  	  return fold_build1 (BIT_NOT_EXPR, type,
  			      build2 (BIT_IOR_EXPR, type,
! 				      fold_convert (type,
! 						    TREE_OPERAND (arg0, 0)),
! 				      fold_convert (type,
! 						    TREE_OPERAND (arg1, 0))));
  	}
  
        /* If arg0 is derived from the address of an object or function, we may
*************** fold_binary (enum tree_code code, tree t
*** 11540,11546 ****
  	  tree tem = build_int_cst (TREE_TYPE (arg1),
  				    GET_MODE_BITSIZE (TYPE_MODE (type)));
  	  tem = const_binop (MINUS_EXPR, tem, arg1, 0);
! 	  return fold_build2 (RROTATE_EXPR, type, arg0, tem);
  	}
  
        /* If we have a rotate of a bit operation with the rotate count and
--- 11542,11548 ----
  	  tree tem = build_int_cst (TREE_TYPE (arg1),
  				    GET_MODE_BITSIZE (TYPE_MODE (type)));
  	  tem = const_binop (MINUS_EXPR, tem, arg1, 0);
! 	  return fold_build2 (RROTATE_EXPR, type, op0, tem);
  	}
  
        /* If we have a rotate of a bit operation with the rotate count and
Index: testsuite/gcc.dg/pr33693.c
===================================================================
*** testsuite/gcc.dg/pr33693.c	(revision 0)
--- testsuite/gcc.dg/pr33693.c	(revision 0)
***************
*** 0 ****
--- 1,8 ----
+ /* { dg-do compile } */
+ 
+ /* This used to ICE with type-checking enabled.  */
+ 
+ unsigned long modify_field (unsigned long mask, long fieldval)
+ {
+   return (~fieldval & ~mask);
+ }
Index: testsuite/gcc.dg/pr33695.c
===================================================================
*** testsuite/gcc.dg/pr33695.c	(revision 0)
--- testsuite/gcc.dg/pr33695.c	(revision 0)
***************
*** 0 ****
--- 1,8 ----
+ /* { dg-do compile } */
+ 
+ /* We used to ICE with type-checking enabled.  */
+ 
+ unsigned int bfstages(int M, float *Utbl, int Ustride)
+ {
+    return ((unsigned int) 1 << M) * Ustride;
+ }
Index: testsuite/gcc.dg/pr33697.c
===================================================================
*** testsuite/gcc.dg/pr33697.c	(revision 0)
--- testsuite/gcc.dg/pr33697.c	(revision 0)
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do compile } */
+ 
+ /* We used to ICE for this with type-checking enabled.  */
+ 
+ typedef signed short gint16;
+ typedef unsigned short guint16;
+ gint16 dissect_old_pflog(gint16 rnr)
+ {
+   return (guint16) ((guint16) ((guint16)rnr >> 8) | (guint16) ((guint16)rnr << 8));
+ }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix PRs 33693, 33695 and 33697
  2007-10-08 15:22 [PATCH] Fix PRs 33693, 33695 and 33697 Richard Guenther
@ 2007-10-08 16:43 ` Andrew Pinski
  2007-10-09  7:57   ` Richard Guenther
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2007-10-08 16:43 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On 10/8/07, Richard Guenther <rguenther@suse.de> wrote:
>         * gcc.dg/pr33693.c: New testcase.
>         * gcc.dg/pr33695.c: Likewise.
>         * gcc.dg/pr33697.c: Likewise.

I think these tests should have been in torture.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix PRs 33693, 33695 and 33697
  2007-10-08 16:43 ` Andrew Pinski
@ 2007-10-09  7:57   ` Richard Guenther
  2007-10-09 10:35     ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Guenther @ 2007-10-09  7:57 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Mon, 8 Oct 2007, Andrew Pinski wrote:

> On 10/8/07, Richard Guenther <rguenther@suse.de> wrote:
> >         * gcc.dg/pr33693.c: New testcase.
> >         * gcc.dg/pr33695.c: Likewise.
> >         * gcc.dg/pr33697.c: Likewise.
> 
> I think these tests should have been in torture.

I thought about this, and types are verified only after gimplification,
so optimization doesn't matter.

Richard.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix PRs 33693, 33695 and 33697
  2007-10-09  7:57   ` Richard Guenther
@ 2007-10-09 10:35     ` Andrew Pinski
  2007-10-09 11:04       ` Richard Guenther
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2007-10-09 10:35 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On 10/9/07, Richard Guenther <rguenther@suse.de> wrote:
> I thought about this, and types are verified only after gimplification,
> so optimization doesn't matter.

But we should be doing more than just after gimplification anyways.  I
don't know why you did not add it as a normal verify pass.

-- Pinski

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix PRs 33693, 33695 and 33697
  2007-10-09 10:35     ` Andrew Pinski
@ 2007-10-09 11:04       ` Richard Guenther
  2007-10-09 18:15         ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Guenther @ 2007-10-09 11:04 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Tue, 9 Oct 2007, Andrew Pinski wrote:

> On 10/9/07, Richard Guenther <rguenther@suse.de> wrote:
> > I thought about this, and types are verified only after gimplification,
> > so optimization doesn't matter.
> 
> But we should be doing more than just after gimplification anyways.  I
> don't know why you did not add it as a normal verify pass.

Because it falls all over ;)  And the immediate goal was to get the
interface between FEs and the middle-end clean, not to fix every error
in the middle-end itself (ok, we catch a lot of fold bugs this way).

But yes, this is future work -- which I delayed until after the tuples
hickup.

Richard.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix PRs 33693, 33695 and 33697
  2007-10-09 11:04       ` Richard Guenther
@ 2007-10-09 18:15         ` Andrew Pinski
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Pinski @ 2007-10-09 18:15 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On 10/9/07, Richard Guenther <rguenther@suse.de> wrote:
> But yes, this is future work -- which I delayed until after the tuples
> hickup.

One I doubt tuples will be ready any time soon anyways. I am willing
to say it won't be ready until at least 4.5 because of expand changes
and getting expand back where it was before tuples.

--Pinski

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-10-09 18:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-08 15:22 [PATCH] Fix PRs 33693, 33695 and 33697 Richard Guenther
2007-10-08 16:43 ` Andrew Pinski
2007-10-09  7:57   ` Richard Guenther
2007-10-09 10:35     ` Andrew Pinski
2007-10-09 11:04       ` Richard Guenther
2007-10-09 18:15         ` Andrew Pinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).