* tree-ssa-alias.c (stmt_kills_ref_p_1): Handle case where
ao_ref_base returns a MEM_REF.
* gcc.dg/tree-ssa/alias-26.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-26.c
b/gcc/testsuite/gcc.dg/tree-ssa/alias-26.c
new file mode 100644
index 0000000..b5625b8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-26.c
@@ -0,0 +1,12 @@
+/* { 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 4db83bd..5120e72 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -2079,6 +2079,7 @@ 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;
+ tree ref_base;
HOST_WIDE_INT offset = 0;
if (!host_integerp (len, 0))
return false;
@@ -2087,8 +2088,11 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref)
&offset);
else if (TREE_CODE (dest) == SSA_NAME)
base = dest;
+ ref_base = ao_ref_base (ref);
if (base
- && base == ao_ref_base (ref))
+ && ((TREE_CODE (ref_base) == MEM_REF
+ && base == TREE_OPERAND (ref_base, 0))