Patchwork [mem-ref2] Fixup tree-affine.c

login
register
mail settings
Submitter Richard Guenther
Date June 25, 2010, 9:26 a.m.
Message ID <alpine.LNX.2.00.1006251125400.1429@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/56895/
State New
Headers show

Comments

Richard Guenther - June 25, 2010, 9:26 a.m.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2010-06-25  Richard Guenther  <rguenther@suse.de>

	* tree-affine.c (tree_to_aff_combination): Handle MEM_REF.

Patch

Index: gcc/tree-affine.c
===================================================================
--- gcc/tree-affine.c	(revision 161366)
+++ gcc/tree-affine.c	(working copy)
@@ -309,6 +309,15 @@  tree_to_aff_combination (tree expr, tree
       return;
 
     case ADDR_EXPR:
+      /* Handle &MEM[ptr + CST] which is equivalent to POINTER_PLUS_EXPR.  */
+      if (TREE_CODE (TREE_OPERAND (expr, 0)) == MEM_REF)
+	{
+	  expr = TREE_OPERAND (expr, 0);
+	  tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
+	  tree_to_aff_combination (TREE_OPERAND (expr, 1), sizetype, &tmp);
+	  aff_combination_add (comb, &tmp);
+	  return;
+	}
       core = get_inner_reference (TREE_OPERAND (expr, 0), &bitsize, &bitpos,
 				  &toffset, &mode, &unsignedp, &volatilep,
 				  false);
@@ -331,6 +340,25 @@  tree_to_aff_combination (tree expr, tree
 	}
       return;
 
+    case MEM_REF:
+      if (TREE_CODE (TREE_OPERAND (expr, 0)) == ADDR_EXPR)
+	tree_to_aff_combination (TREE_OPERAND (TREE_OPERAND (expr, 0), 0),
+				 type, comb);
+      else if (integer_zerop (TREE_OPERAND (expr, 1)))
+	{
+	  aff_combination_elt (comb, type, expr);
+	  return;
+	}
+      else
+	aff_combination_elt (comb, type,
+			     build2 (MEM_REF, TREE_TYPE (expr),
+				     TREE_OPERAND (expr, 0),
+				     build_int_cst
+				      (TREE_TYPE (TREE_OPERAND (expr, 1)), 0)));
+      tree_to_aff_combination (TREE_OPERAND (expr, 1), sizetype, &tmp);
+      aff_combination_add (comb, &tmp);
+      return;
+
     default:
       break;
     }