From e6c705fbf686673722554bfa5474511e0db53776 Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 11 Nov 2013 20:56:19 +0000 Subject: [PATCH] 2013-11-11 Marc Glisse Jeff Law gcc/ * tree-ssa-alias.c (stmt_kills_ref_p_1): Use ao_ref_init_from_ptr_and_size for builtins. gcc/testsuite/ * gcc.dg/tree-ssa/alias-27.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204686 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 +++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/tree-ssa/alias-27.c | 11 ++++++++ gcc/tree-ssa-alias.c | 45 ++++++++++++++++++++------------ 4 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/alias-27.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a140a62851a..bc418fea7ab 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-11-11 Marc Glisse + Jeff Law + + * tree-ssa-alias.c (stmt_kills_ref_p_1): Use + ao_ref_init_from_ptr_and_size for builtins. + 2013-11-11 Uros Bizjak H.J. Lu diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 74a2d56622e..9a527e02050 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-11-11 Marc Glisse + Jeff Law + + * gcc.dg/tree-ssa/alias-27.c: New testcase. + 2013-11-11 Uros Bizjak PR target/58853 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-27.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-27.c new file mode 100644 index 00000000000..91c737eae25 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-27.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +void f (long *p) { + *p = 42; + p[4] = 42; + __builtin_memset (p, 0, 100); +} + +/* { dg-final { scan-tree-dump-not "= 42" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 278599591e6..161a66a8b74 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -2008,9 +2008,10 @@ static bool stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref) { /* For a must-alias check we need to be able to constrain - the access properly. */ - ao_ref_base (ref); - if (ref->max_size == -1) + the access properly. + FIXME: except for BUILTIN_FREE. */ + if (!ao_ref_base (ref) + || ref->max_size == -1) return false; if (gimple_has_lhs (stmt) @@ -2097,23 +2098,33 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref) { tree dest = gimple_call_arg (stmt, 0); tree len = gimple_call_arg (stmt, 2); - tree base = NULL_TREE; - HOST_WIDE_INT offset = 0; if (!host_integerp (len, 0)) return false; - if (TREE_CODE (dest) == ADDR_EXPR) - base = get_addr_base_and_unit_offset (TREE_OPERAND (dest, 0), - &offset); - else if (TREE_CODE (dest) == SSA_NAME) - base = dest; - if (base - && base == ao_ref_base (ref)) + tree rbase = ref->base; + double_int roffset = double_int::from_shwi (ref->offset); + ao_ref dref; + ao_ref_init_from_ptr_and_size (&dref, dest, len); + tree base = ao_ref_base (&dref); + double_int offset = double_int::from_shwi (dref.offset); + double_int bpu = double_int::from_uhwi (BITS_PER_UNIT); + if (!base || dref.size == -1) + return false; + if (TREE_CODE (base) == MEM_REF) + { + if (TREE_CODE (rbase) != MEM_REF) + return false; + // Compare pointers. + offset += bpu * mem_ref_offset (base); + roffset += bpu * mem_ref_offset (rbase); + base = TREE_OPERAND (base, 0); + rbase = TREE_OPERAND (rbase, 0); + } + if (base == rbase) { - HOST_WIDE_INT size = TREE_INT_CST_LOW (len); - if (offset <= ref->offset / BITS_PER_UNIT - && (offset + size - >= ((ref->offset + ref->max_size + BITS_PER_UNIT - 1) - / BITS_PER_UNIT))) + double_int size = bpu * tree_to_double_int (len); + double_int rsize = double_int::from_uhwi (ref->max_size); + if (offset.sle (roffset) + && (roffset + rsize).sle (offset + size)) return true; } break; -- 2.11.4.GIT