diff options
author | Richard Biener <rguenther@suse.de> | 2020-02-04 15:17:01 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2020-02-04 15:18:25 +0100 |
commit | 5124c34fcc62f0f880ae947542678e28aa2ce703 (patch) | |
tree | ed149fabf769e532c99a6fe6f1eecad4cafc740f /gcc/match.pd | |
parent | 9bc5bea1f3f0ce3927fd86ce728641d087f3d3b5 (diff) |
tree-optimization/93538 - add missing comparison folding case
This adds back a folding that worked in GCC 4.5 times by amending
the pattern that handles other cases of address vs. SSA name
comparisons.
2020-02-04 Richard Biener <rguenther@suse.de>
PR tree-optimization/93538
* match.pd (addr EQ/NE ptr): Amend to handle &ptr->x EQ/NE ptr.
* gcc.dg/tree-ssa/forwprop-38.c: New testcase.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index 5fee394e7af..73834c25593 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4267,19 +4267,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) { constant_boolean_node (above ? false : true, type); })))))))))))) (for cmp (eq ne) - /* A local variable can never be pointed to by - the default SSA name of an incoming parameter. - SSA names are canonicalized to 2nd place. */ (simplify + /* SSA names are canonicalized to 2nd place. */ (cmp addr@0 SSA_NAME@1) - (if (SSA_NAME_IS_DEFAULT_DEF (@1) - && TREE_CODE (SSA_NAME_VAR (@1)) == PARM_DECL) - (with { tree base = get_base_address (TREE_OPERAND (@0, 0)); } - (if (TREE_CODE (base) == VAR_DECL - && auto_var_in_fn_p (base, current_function_decl)) - (if (cmp == NE_EXPR) - { constant_boolean_node (true, type); } - { constant_boolean_node (false, type); })))))) + (with + { poly_int64 off; tree base; } + /* A local variable can never be pointed to by + the default SSA name of an incoming parameter. */ + (if (SSA_NAME_IS_DEFAULT_DEF (@1) + && TREE_CODE (SSA_NAME_VAR (@1)) == PARM_DECL + && (base = get_base_address (TREE_OPERAND (@0, 0))) + && TREE_CODE (base) == VAR_DECL + && auto_var_in_fn_p (base, current_function_decl)) + (if (cmp == NE_EXPR) + { constant_boolean_node (true, type); } + { constant_boolean_node (false, type); }) + /* If the address is based on @1 decide using the offset. */ + (if ((base = get_addr_base_and_unit_offset (TREE_OPERAND (@0, 0), &off)) + && TREE_CODE (base) == MEM_REF + && TREE_OPERAND (base, 0) == @1) + (with { off += mem_ref_offset (base).force_shwi (); } + (if (known_ne (off, 0)) + { constant_boolean_node (cmp == NE_EXPR, type); } + (if (known_eq (off, 0)) + { constant_boolean_node (cmp == EQ_EXPR, type); })))))))) /* Equality compare simplifications from fold_binary */ (for cmp (eq ne) |