From d68e9408609c6b794b43fdd6c19b4057bb4f200f Mon Sep 17 00:00:00 2001 From: rguenth Date: Mon, 27 May 2013 12:44:29 +0000 Subject: [PATCH] 2013-05-27 Richard Biener Revert PR middle-end/57381 * fold-const.c (operand_equal_p): Compare FIELD_DECLs with OEP_CONSTANT_ADDRESS_OF retained. PR tree-optimization/57417 * tree-ssa-sccvn.c (vn_reference_fold_indirect): Fix test for unchanged base. (set_ssa_val_to): Compare addresses using get_addr_base_and_unit_offset. * gcc.dg/torture/pr57417.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@199356 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 13 +++++++++++++ gcc/fold-const.c | 4 ++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr57417.c | 12 ++++++++++++ gcc/tree-ssa-sccvn.c | 15 +++++++++++++-- 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr57417.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a8c366b6086..8b7bed89d4b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2013-05-27 Richard Biener + + Revert + PR middle-end/57381 + * fold-const.c (operand_equal_p): Compare FIELD_DECLs with + OEP_CONSTANT_ADDRESS_OF retained. + + PR tree-optimization/57417 + * tree-ssa-sccvn.c (vn_reference_fold_indirect): Fix test + for unchanged base. + (set_ssa_val_to): Compare addresses using + get_addr_base_and_unit_offset. + 2013-05-27 Joern Rennecke PR rtl-optimization/56833 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 38db3f1d832..a2b7ac18312 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2664,10 +2664,10 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) case COMPONENT_REF: /* Handle operand 2 the same as for ARRAY_REF. Operand 0 may be NULL when we're called to compare MEM_EXPRs. */ - if (!OP_SAME_WITH_NULL (0) || !OP_SAME (1)) + if (!OP_SAME_WITH_NULL (0)) return 0; flags &= ~OEP_CONSTANT_ADDRESS_OF; - return OP_SAME_WITH_NULL (2); + return OP_SAME (1) && OP_SAME_WITH_NULL (2); case BIT_FIELD_REF: if (!OP_SAME (0)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d0f01c84c01..7cf47c4f514 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2013-05-27 Richard Biener + PR tree-optimization/57417 + * gcc.dg/torture/pr57417.c: New testcase. + +2013-05-27 Richard Biener + PR tree-optimization/57396 * gfortran.fortran-torture/execute/pr57396.f90: New testcase. diff --git a/gcc/testsuite/gcc.dg/torture/pr57417.c b/gcc/testsuite/gcc.dg/torture/pr57417.c new file mode 100644 index 00000000000..6eac6f932b8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr57417.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ + +int a, b; +volatile int *c; + +void foo () +{ + volatile int d[1]; + b = 0; + for (;; a--) + c = &d[b]; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 0e7a74c2a9c..6886efbe3eb 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1145,7 +1145,7 @@ vn_reference_fold_indirect (vec *ops, addr_base = get_addr_base_and_unit_offset (TREE_OPERAND (op->op0, 0), &addr_offset); gcc_checking_assert (addr_base && TREE_CODE (addr_base) != MEM_REF); - if (addr_base != op->op0) + if (addr_base != TREE_OPERAND (op->op0, 0)) { double_int off = tree_to_double_int (mem_op->op0); off = off.sext (TYPE_PRECISION (TREE_TYPE (mem_op->op0))); @@ -2608,6 +2608,7 @@ static inline bool set_ssa_val_to (tree from, tree to) { tree currval = SSA_VAL (from); + HOST_WIDE_INT toff, coff; if (from != to) { @@ -2643,7 +2644,17 @@ set_ssa_val_to (tree from, tree to) print_generic_expr (dump_file, to, 0); } - if (currval != to && !operand_equal_p (currval, to, OEP_PURE_SAME)) + if (currval != to + && !operand_equal_p (currval, to, 0) + /* ??? For addresses involving volatile objects or types operand_equal_p + does not reliably detect ADDR_EXPRs as equal. We know we are only + getting invariant gimple addresses here, so can use + get_addr_base_and_unit_offset to do this comparison. */ + && !(TREE_CODE (currval) == ADDR_EXPR + && TREE_CODE (to) == ADDR_EXPR + && (get_addr_base_and_unit_offset (TREE_OPERAND (currval, 0), &coff) + == get_addr_base_and_unit_offset (TREE_OPERAND (to, 0), &toff)) + && coff == toff)) { VN_INFO (from)->valnum = to; if (dump_file && (dump_flags & TDF_DETAILS)) -- 2.11.4.GIT