As requested in https://inbox.sourceware.org/gcc-patches/CAFiYyc1jzZSZNhTas-DdMBFOzH1p96oGN=OVj6fyjt8HzDUyCA@mail.gmail.com/T/#u.
This introduces fold_before_rtl_expansion_p to replace
`(cfun->curr_properties & PROP_last_full_fold) != 0`.
I am not a fan of include tree-pass.h in gimple-fold.h but that was the
only way to reduce the number of changes.
Bootrapped and tested on x86_64-linux-gnu.
PR tree-optimization/122142
gcc/ChangeLog:
* generic-match-head.cc: Include gimple-iterator.h
and gimple-fold.h.
* gimple-fold.cc (gimple_fold_builtin_constant_p): Use
fold_before_rtl_expansion_p.
(gimple_fold_builtin_assume_aligned): Likewise.
(gimple_fold_builtin_stdarg): Likewise.
(gimple_fold_call): Likewise.
* gimple-fold.h: Include "tree-pass.h".
(fold_before_rtl_expansion_p): New function.
* match.pd: Use fold_before_rtl_expansion_p
instead of `cfun->curr_properties & PROP_last_full_fold`.
* tree-ssa-forwprop.cc (simplify_builtin_memcmp): Likewise.
(optimize_stack_restore): Likewise.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
#include "tree-pass.h"
#include "attribs.h"
#include "asan.h"
+#include "gimple-iterator.h"
+#include "gimple-fold.h"
/* Routine to determine if the types T1 and T2 are effectively
the same for GENERIC. If T1 or T2 is not a type, the test
#include "stor-layout.h"
#include "dumpfile.h"
#include "gimple-iterator.h"
+#include "tree-pass.h"
#include "gimple-fold.h"
#include "gimplify.h"
#include "tree-into-ssa.h"
#include "varasm.h"
#include "internal-fn.h"
#include "gimple-range.h"
-#include "tree-pass.h"
enum strlen_range_kind {
/* Compute the exact constant string length. */
/* Resolve __builtin_constant_p. If it hasn't been
folded to integer_one_node by now, it's fairly
certain that the value simply isn't constant. */
- if (!result
- && (cfun->curr_properties & PROP_last_full_fold))
+ if (!result && fold_before_rtl_expansion_p ())
result = integer_zero_node;
if (!result)
static bool
gimple_fold_builtin_assume_aligned (gimple_stmt_iterator *gsi)
{
- if (!(cfun->curr_properties & PROP_last_full_fold))
+ if (!fold_before_rtl_expansion_p ())
return false;
gcall *call = as_a<gcall*>(gsi_stmt (*gsi));
gimple_fold_builtin_stdarg (gimple_stmt_iterator *gsi, gcall *call)
{
/* These shouldn't be folded before pass_stdarg. */
- if (!(cfun->curr_properties & PROP_last_full_fold))
+ if (!fold_before_rtl_expansion_p ())
return false;
tree callee, lhs, rhs, cfun_va_list;
case IFN_ASSUME:
/* Remove .ASSUME calls during the last fold since it is no
longer needed. */
- if (cfun->curr_properties & PROP_last_full_fold)
+ if (fold_before_rtl_expansion_p ())
replace_call_with_value (gsi, NULL_TREE);
break;
case IFN_BUILTIN_EXPECT:
#ifndef GCC_GIMPLE_FOLD_H
#define GCC_GIMPLE_FOLD_H
+#include "tree-pass.h"
+
extern tree canonicalize_constructor_val (tree, tree);
extern tree get_symbol_constant_value (tree);
struct c_strlen_data;
extern tree gimple_simplify (combined_fn, tree, tree, tree, tree,
gimple_seq *, tree (*)(tree));
+/* Returns true if we are doing the fold before expansion to rtl. */
+inline bool
+fold_before_rtl_expansion_p ()
+{
+ if (!cfun)
+ return false;
+ return (cfun->curr_properties & PROP_last_full_fold) != 0;
+}
+
#endif /* GCC_GIMPLE_FOLD_H */
expr_not_equal_to had a chance to match. Otherwise we'd do
pretty much always just the second case. */
&& cfun
- && ((cfun->curr_properties & PROP_last_full_fold) != 0
+ && (fold_before_rtl_expansion_p ()
|| !flag_tree_vrp
|| optimize_debug))
(orotate @0
(plus:c
(plus (rshift @0 integer_onep@1) (rshift @2 @1))
(bit_and (bit_ior @0 @2) integer_onep@3))
- (if (cfun && (cfun->curr_properties & PROP_last_full_fold) != 0
+ (if (fold_before_rtl_expansion_p ()
&& VECTOR_TYPE_P (type)
&& direct_internal_fn_supported_p (IFN_AVG_CEIL, type, OPTIMIZE_FOR_BOTH))
(IFN_AVG_CEIL @0 @2)))
(minus
(bit_ior @0 @2)
(rshift (bit_xor @0 @2) integer_onep@1))
- (if (cfun && (cfun->curr_properties & PROP_last_full_fold) != 0
+ (if (fold_before_rtl_expansion_p ()
&& VECTOR_TYPE_P (type)
&& direct_internal_fn_supported_p (IFN_AVG_CEIL, type, OPTIMIZE_FOR_BOTH))
(IFN_AVG_CEIL @0 @2)))
/* Replace memcmp with memcmp_eq if the above fails. */
if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt)) == BUILT_IN_MEMCMP_EQ)
return false;
- if (!(cfun->curr_properties & (PROP_last_full_fold)))
+ if (!fold_before_rtl_expansion_p ())
return false;
gimple_call_set_fndecl (stmt, builtin_decl_explicit (BUILT_IN_MEMCMP_EQ));
update_stmt (stmt);
static bool
optimize_stack_restore (gimple_stmt_iterator *gsi, gimple *call)
{
- if (!(cfun->curr_properties & PROP_last_full_fold))
+ if (!fold_before_rtl_expansion_p ())
return false;
tree callee;
gimple *stmt;