This adds folding of &MEM[CST + CST] to 
build_fold_addr_expr_with_type_loc.

Bootstrap and regtest pending on x86_64-unknown-linux-gnu.

Richard.

2012-03-06  Richard Guenther  <rguent...@suse.de>

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

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c    (revision 184981)
--- gcc/fold-const.c    (working copy)
*************** build_fold_addr_expr_with_type_loc (loca
*** 7626,7633 ****
        t = build1_loc (loc, NOP_EXPR, ptrtype, t);
      }
    else if (TREE_CODE (t) == MEM_REF
!       && integer_zerop (TREE_OPERAND (t, 1)))
!     return TREE_OPERAND (t, 0);
    else if (TREE_CODE (t) == VIEW_CONVERT_EXPR)
      {
        t = build_fold_addr_expr_loc (loc, TREE_OPERAND (t, 0));
--- 7626,7638 ----
        t = build1_loc (loc, NOP_EXPR, ptrtype, t);
      }
    else if (TREE_CODE (t) == MEM_REF
!          && integer_zerop (TREE_OPERAND (t, 1)))
!     return fold_convert (ptrtype, 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));

Reply via email to