summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-ccp.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/tree-ssa-ccp.c')
-rw-r--r--gcc/tree-ssa-ccp.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 0365697fc85..a7d5be32e31 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -851,6 +851,31 @@ ccp_visit_phi_node (gimple phi)
return SSA_PROP_NOT_INTERESTING;
}
+/* Return true if we may propagate the address expression ADDR into the
+ dereference DEREF and cancel them. */
+
+bool
+may_propagate_address_into_dereference (tree addr, tree deref)
+{
+ gcc_assert (INDIRECT_REF_P (deref)
+ && TREE_CODE (addr) == ADDR_EXPR);
+
+ /* If the address is invariant then we do not need to preserve restrict
+ qualifications. But we do need to preserve volatile qualifiers until
+ we can annotate the folded dereference itself properly. */
+ if (is_gimple_min_invariant (addr)
+ && (!TREE_THIS_VOLATILE (deref)
+ || TYPE_VOLATILE (TREE_TYPE (addr))))
+ return useless_type_conversion_p (TREE_TYPE (deref),
+ TREE_TYPE (TREE_OPERAND (addr, 0)));
+
+ /* Else both the address substitution and the folding must result in
+ a valid useless type conversion sequence. */
+ return (useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (deref, 0)),
+ TREE_TYPE (addr))
+ && useless_type_conversion_p (TREE_TYPE (deref),
+ TREE_TYPE (TREE_OPERAND (addr, 0))));
+}
/* CCP specific front-end to the non-destructive constant folding
routines.
@@ -897,12 +922,8 @@ ccp_fold (gimple stmt)
prop_value_t *val = get_value (TREE_OPERAND (*base, 0));
if (val->lattice_val == CONSTANT
&& TREE_CODE (val->value) == ADDR_EXPR
- && useless_type_conversion_p
- (TREE_TYPE (TREE_OPERAND (*base, 0)),
- TREE_TYPE (val->value))
- && useless_type_conversion_p
- (TREE_TYPE (*base),
- TREE_TYPE (TREE_OPERAND (val->value, 0))))
+ && may_propagate_address_into_dereference
+ (val->value, *base))
{
/* We need to return a new tree, not modify the IL
or share parts of it. So play some tricks to