fold-const.c (build_fold_addr_expr_with_type_loc): Fold MEM_REF with constant pointer...
authorRichard Guenther <rguenther@suse.de>
Tue, 6 Mar 2012 13:16:50 +0000 (13:16 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 6 Mar 2012 13:16:50 +0000 (13:16 +0000)
2012-03-06  Richard Guenther  <rguenther@suse.de>

* fold-const.c (build_fold_addr_expr_with_type_loc): Fold
MEM_REF with constant pointer operand.

From-SVN: r184988

gcc/ChangeLog
gcc/fold-const.c

index 3b88179294ba81c1f905f53b69f19fc1bd54949b..5ce9dc65c6713028762dda11de381e0742e33293 100644 (file)
@@ -1,3 +1,8 @@
+2012-03-06  Richard Guenther  <rguenther@suse.de>
+
+       * fold-const.c (build_fold_addr_expr_with_type_loc): Fold
+       MEM_REF with constant pointer operand.
+
 2012-03-06  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/52493
index 6492f1167861cf00cfd3e964b50468583c9c76cb..0f806752dd36a80d67d7bb47f36b38df83301e6f 100644 (file)
@@ -7626,8 +7626,13 @@ build_fold_addr_expr_with_type_loc (location_t loc, tree t, tree ptrtype)
        t = build1_loc (loc, NOP_EXPR, ptrtype, t);
     }
   else if (TREE_CODE (t) == MEM_REF
-      && integer_zerop (TREE_OPERAND (t, 1)))
+          && integer_zerop (TREE_OPERAND (t, 1)))
     return TREE_OPERAND (t, 0);
+  else if (TREE_CODE (t) == MEM_REF
+          && TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST)
+    return fold_binary (POINTER_PLUS_EXPR, ptrtype,
+                       TREE_OPERAND (t, 0),
+                       convert_to_ptrofftype (TREE_OPERAND (t, 1)));
   else if (TREE_CODE (t) == VIEW_CONVERT_EXPR)
     {
       t = build_fold_addr_expr_loc (loc, TREE_OPERAND (t, 0));