Commit bd68a3a7 by Richard Henderson Committed by Richard Henderson

Avoid CSE of MEMs in different address spaces

        * cselib.c (add_mem_for_addr): Compare address spaces when
        matching memories.
        (cselib_lookup_mem): Likewise.
        * fold-const.c (operand_equal_p): Check address spaces of
        pointer types before checking integer constants.

From-SVN: r229998
parent f0ebde5a
2015-11-09 Richard Henderson <rth@redhat.com> 2015-11-09 Richard Henderson <rth@redhat.com>
* cselib.c (add_mem_for_addr): Compare address spaces when
matching memories.
(cselib_lookup_mem): Likewise.
* fold-const.c (operand_equal_p): Check address spaces of
pointer types before checking integer constants.
PR tree-opt/66768 PR tree-opt/66768
* tree-ssa-address.c (create_mem_ref_raw): Use a pointer of * tree-ssa-address.c (create_mem_ref_raw): Use a pointer of
the correct type for the base. the correct type for the base.
...@@ -1329,15 +1329,15 @@ new_cselib_val (unsigned int hash, machine_mode mode, rtx x) ...@@ -1329,15 +1329,15 @@ new_cselib_val (unsigned int hash, machine_mode mode, rtx x)
static void static void
add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x) add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x)
{ {
struct elt_loc_list *l;
addr_elt = canonical_cselib_val (addr_elt); addr_elt = canonical_cselib_val (addr_elt);
mem_elt = canonical_cselib_val (mem_elt); mem_elt = canonical_cselib_val (mem_elt);
/* Avoid duplicates. */ /* Avoid duplicates. */
for (l = mem_elt->locs; l; l = l->next) addr_space_t as = MEM_ADDR_SPACE (x);
for (elt_loc_list *l = mem_elt->locs; l; l = l->next)
if (MEM_P (l->loc) if (MEM_P (l->loc)
&& CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt) && CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt
&& MEM_ADDR_SPACE (l->loc) == as)
{ {
promote_debug_loc (l); promote_debug_loc (l);
return; return;
...@@ -1364,7 +1364,6 @@ cselib_lookup_mem (rtx x, int create) ...@@ -1364,7 +1364,6 @@ cselib_lookup_mem (rtx x, int create)
cselib_val **slot; cselib_val **slot;
cselib_val *addr; cselib_val *addr;
cselib_val *mem_elt; cselib_val *mem_elt;
struct elt_list *l;
if (MEM_VOLATILE_P (x) || mode == BLKmode if (MEM_VOLATILE_P (x) || mode == BLKmode
|| !cselib_record_memory || !cselib_record_memory
...@@ -1379,15 +1378,20 @@ cselib_lookup_mem (rtx x, int create) ...@@ -1379,15 +1378,20 @@ cselib_lookup_mem (rtx x, int create)
addr = cselib_lookup (XEXP (x, 0), addr_mode, create, mode); addr = cselib_lookup (XEXP (x, 0), addr_mode, create, mode);
if (! addr) if (! addr)
return 0; return 0;
addr = canonical_cselib_val (addr); addr = canonical_cselib_val (addr);
/* Find a value that describes a value of our mode at that address. */ /* Find a value that describes a value of our mode at that address. */
for (l = addr->addr_list; l; l = l->next) addr_space_t as = MEM_ADDR_SPACE (x);
for (elt_list *l = addr->addr_list; l; l = l->next)
if (GET_MODE (l->elt->val_rtx) == mode) if (GET_MODE (l->elt->val_rtx) == mode)
{ {
for (elt_loc_list *l2 = l->elt->locs; l2; l2 = l2->next)
if (MEM_P (l2->loc) && MEM_ADDR_SPACE (l2->loc) == as)
{
promote_debug_loc (l->elt->locs); promote_debug_loc (l->elt->locs);
return l->elt; return l->elt;
} }
}
if (! create) if (! create)
return 0; return 0;
......
...@@ -2697,6 +2697,13 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) ...@@ -2697,6 +2697,13 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1)) if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
return 0; return 0;
/* We cannot consider pointers to different address space equal. */
if (POINTER_TYPE_P (TREE_TYPE (arg0))
&& POINTER_TYPE_P (TREE_TYPE (arg1))
&& (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0)))
!= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1)))))
return 0;
/* Check equality of integer constants before bailing out due to /* Check equality of integer constants before bailing out due to
precision differences. */ precision differences. */
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
...@@ -2719,13 +2726,6 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) ...@@ -2719,13 +2726,6 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
!= POINTER_TYPE_P (TREE_TYPE (arg1))) != POINTER_TYPE_P (TREE_TYPE (arg1)))
return 0; return 0;
/* We cannot consider pointers to different address space equal. */
if (POINTER_TYPE_P (TREE_TYPE (arg0))
&& POINTER_TYPE_P (TREE_TYPE (arg1))
&& (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0)))
!= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1)))))
return 0;
/* If both types don't have the same precision, then it is not safe /* If both types don't have the same precision, then it is not safe
to strip NOPs. */ to strip NOPs. */
if (element_precision (TREE_TYPE (arg0)) if (element_precision (TREE_TYPE (arg0))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment