diff mbox

Fix PR54211

Message ID 1344561084.18792.11.camel@gnopaine
State New
Headers show

Commit Message

Bill Schmidt Aug. 10, 2012, 1:11 a.m. UTC
Fix a thinko in strength reduction.  I was checking the type of the
wrong operand to determine whether address arithmetic should be used in
replacing expressions.  This produced a spurious POINTER_PLUS_EXPR when
an address was converted to an unsigned long and back again.

Bootstrapped and tested on powerpc64-unknown-linux-gnu with no new
regressions.  Ok for trunk?

Thanks,
Bill


gcc:

2012-08-09  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR middle-end/54211
	* gimple-ssa-strength-reduction.c (analyze_candidates_and_replace):
	Use cand_type to determine whether pointer arithmetic will be generated.

gcc/testsuite:

2012-08-09  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR middle-end/54211
	* gcc.dg/tree-ssa/pr54211.c: New test.

Comments

Richard Biener Aug. 10, 2012, 8:51 a.m. UTC | #1
On Thu, 9 Aug 2012, William J. Schmidt wrote:

> Fix a thinko in strength reduction.  I was checking the type of the
> wrong operand to determine whether address arithmetic should be used in
> replacing expressions.  This produced a spurious POINTER_PLUS_EXPR when
> an address was converted to an unsigned long and back again.
> 
> Bootstrapped and tested on powerpc64-unknown-linux-gnu with no new
> regressions.  Ok for trunk?

Ok.

Thanks,
Richard.

> Thanks,
> Bill
> 
> 
> gcc:
> 
> 2012-08-09  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
> 
> 	PR middle-end/54211
> 	* gimple-ssa-strength-reduction.c (analyze_candidates_and_replace):
> 	Use cand_type to determine whether pointer arithmetic will be generated.
> 
> gcc/testsuite:
> 
> 2012-08-09  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
> 
> 	PR middle-end/54211
> 	* gcc.dg/tree-ssa/pr54211.c: New test.
> 
> 
> Index: gcc/testsuite/gcc.dg/tree-ssa/pr54211.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/tree-ssa/pr54211.c	(revision 0)
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr54211.c	(revision 0)
> @@ -0,0 +1,28 @@
> +/* { dg-do compile } */
> +/* { dg-options "-Os" } */
> +
> +int a, b;
> +unsigned char e;
> +void fn1 ()
> +{
> +    unsigned char *c=0;
> +    for (;; a++)
> +    {
> +        unsigned char d = *(c + b);
> +        for (; &e<&d; c++)
> +            goto Found_Top;
> +    }
> +Found_Top:
> +    if (0)
> +        goto Empty_Bitmap;
> +    for (;; a++)
> +    {
> +        unsigned char *e = c + b;
> +        for (; c < e; c++)
> +            goto Found_Bottom;
> +        c -= b;
> +    }
> +Found_Bottom:
> +Empty_Bitmap:
> +    ;
> +}
> Index: gcc/gimple-ssa-strength-reduction.c
> ===================================================================
> --- gcc/gimple-ssa-strength-reduction.c	(revision 190260)
> +++ gcc/gimple-ssa-strength-reduction.c	(working copy)
> @@ -2534,7 +2534,7 @@ analyze_candidates_and_replace (void)
>  	  /* Determine whether we'll be generating pointer arithmetic
>  	     when replacing candidates.  */
>  	  address_arithmetic_p = (c->kind == CAND_ADD
> -				  && POINTER_TYPE_P (TREE_TYPE (c->base_expr)));
> +				  && POINTER_TYPE_P (c->cand_type));
>  
>  	  /* If all candidates have already been replaced under other
>  	     interpretations, nothing remains to be done.  */
> 
> 
>
diff mbox

Patch

Index: gcc/testsuite/gcc.dg/tree-ssa/pr54211.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr54211.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr54211.c	(revision 0)
@@ -0,0 +1,28 @@ 
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+
+int a, b;
+unsigned char e;
+void fn1 ()
+{
+    unsigned char *c=0;
+    for (;; a++)
+    {
+        unsigned char d = *(c + b);
+        for (; &e<&d; c++)
+            goto Found_Top;
+    }
+Found_Top:
+    if (0)
+        goto Empty_Bitmap;
+    for (;; a++)
+    {
+        unsigned char *e = c + b;
+        for (; c < e; c++)
+            goto Found_Bottom;
+        c -= b;
+    }
+Found_Bottom:
+Empty_Bitmap:
+    ;
+}
Index: gcc/gimple-ssa-strength-reduction.c
===================================================================
--- gcc/gimple-ssa-strength-reduction.c	(revision 190260)
+++ gcc/gimple-ssa-strength-reduction.c	(working copy)
@@ -2534,7 +2534,7 @@  analyze_candidates_and_replace (void)
 	  /* Determine whether we'll be generating pointer arithmetic
 	     when replacing candidates.  */
 	  address_arithmetic_p = (c->kind == CAND_ADD
-				  && POINTER_TYPE_P (TREE_TYPE (c->base_expr)));
+				  && POINTER_TYPE_P (c->cand_type));
 
 	  /* If all candidates have already been replaced under other
 	     interpretations, nothing remains to be done.  */