aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.cc')
-rw-r--r--gcc/fold-const.cc31
1 files changed, 22 insertions, 9 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 1275ef7..35fcf50 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -7246,6 +7246,12 @@ tree_swap_operands_p (const_tree arg0, const_tree arg1)
if (TREE_CONSTANT (arg0))
return true;
+ /* Put invariant address in arg1. */
+ if (is_gimple_invariant_address (arg1))
+ return false;
+ if (is_gimple_invariant_address (arg0))
+ return true;
+
/* It is preferable to swap two SSA_NAME to ensure a canonical form
for commutative and comparison operators. Ensuring a canonical
form allows the optimizers to find additional redundancies without
@@ -9911,22 +9917,29 @@ pointer_may_wrap_p (tree base, tree offset, poly_int64 bitpos)
static int
maybe_nonzero_address (tree decl)
{
+ if (!DECL_P (decl))
+ return -1;
+
/* Normally, don't do anything for variables and functions before symtab is
built; it is quite possible that DECL will be declared weak later.
But if folding_initializer, we need a constant answer now, so create
the symtab entry and prevent later weak declaration. */
- if (DECL_P (decl) && decl_in_symtab_p (decl))
- if (struct symtab_node *symbol
- = (folding_initializer
- ? symtab_node::get_create (decl)
- : symtab_node::get (decl)))
- return symbol->nonzero_address ();
+ if (decl_in_symtab_p (decl))
+ {
+ if (struct symtab_node *symbol
+ = (folding_initializer
+ ? symtab_node::get_create (decl)
+ : symtab_node::get (decl)))
+ return symbol->nonzero_address ();
+ }
+ else if (folding_cxx_constexpr)
+ /* Anything that doesn't go in the symtab has non-zero address. */
+ return 1;
/* Function local objects are never NULL. */
- if (DECL_P (decl)
- && (DECL_CONTEXT (decl)
+ if (DECL_CONTEXT (decl)
&& TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
- && auto_var_in_fn_p (decl, DECL_CONTEXT (decl))))
+ && auto_var_in_fn_p (decl, DECL_CONTEXT (decl)))
return 1;
return -1;