This is the first patch in removing fold_all_builtins pass.
We want to fold __builtin_constant_p into 0 if we know the argument can't be
a constant. So currently that is done in fab pass (though ranger handles it now too).
Instead of having fab do it we can check PROP_last_full_fold if set and set it
to 0 instead.
Note for -Og, fab was the only place which did this conversion, so we need to
set PROP_last_full_fold for it; later on fab will be removed and isel will do
it instead but that is for another day.
Also instead of going through fold_call_stmt to call fold_builtin_constant_p,
fold_builtin_constant_p is called directly from gimple_fold_builtin_constant_p.
This should speed up the compiling slight :).
Note fab was originally added to do this transformation during the development
of the ssa branch.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/121762
gcc/ChangeLog:
* builtins.cc (fold_builtin_constant_p): Make non-static.
* builtins.h (fold_builtin_constant_p): New declaration.
* gimple-fold.cc (gimple_fold_builtin_constant_p): New function.
(gimple_fold_builtin): Call gimple_fold_builtin_constant_p
for BUILT_IN_CONSTANT_P.
* tree-ssa-ccp.cc (pass_fold_builtins::execute): Set PROP_last_full_fold
on curr_properties. Remove handling of BUILT_IN_CONSTANT_P.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
static tree stabilize_va_list_loc (location_t, tree, int);
static rtx expand_builtin_expect (tree, rtx);
static rtx expand_builtin_expect_with_probability (tree, rtx);
-static tree fold_builtin_constant_p (tree);
static tree fold_builtin_classify_type (tree);
static tree fold_builtin_strlen (location_t, tree, tree, tree);
static tree fold_builtin_inf (location_t, tree, int);
/* Fold a call to __builtin_constant_p, if we know its argument ARG will
evaluate to a constant. */
-static tree
+tree
fold_builtin_constant_p (tree arg)
{
/* We return 1 for a numeric type that's known to be a constant
extern rtx expand_builtin (tree, rtx, rtx, machine_mode, int);
extern enum built_in_function builtin_mathfn_code (const_tree);
extern tree fold_builtin_expect (location_t, tree, tree, tree, tree);
+extern tree fold_builtin_constant_p (tree);
extern bool avoid_folding_inline_builtin (tree);
extern tree fold_call_expr (location_t, tree, bool);
extern tree fold_builtin_call_array (location_t, tree, tree, int, tree *);
#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. */
return true;
}
+/* Fold __builtin_constant_p builtin. */
+
+static bool
+gimple_fold_builtin_constant_p (gimple_stmt_iterator *gsi)
+{
+ gcall *call = as_a<gcall*>(gsi_stmt (*gsi));
+
+ if (gimple_call_num_args (call) != 1)
+ return false;
+
+ tree arg = gimple_call_arg (call, 0);
+ tree result = fold_builtin_constant_p (arg);
+
+ /* 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))
+ result = integer_zero_node;
+
+ if (!result)
+ return false;
+
+ gimplify_and_update_call_from_tree (gsi, result);
+ return true;
+}
+
/* Fold the non-target builtin at *GSI and return whether any simplification
was made. */
case BUILT_IN_CLEAR_PADDING:
return gimple_fold_builtin_clear_padding (gsi);
+ case BUILT_IN_CONSTANT_P:
+ return gimple_fold_builtin_constant_p (gsi);
+
default:;
}
basic_block bb;
unsigned int todoflags = 0;
+ /* Set last full fold prop if not already set. */
+ fun->curr_properties |= PROP_last_full_fold;
+
FOR_EACH_BB_FN (bb, fun)
{
gimple_stmt_iterator i;
tree result = NULL_TREE;
switch (DECL_FUNCTION_CODE (callee))
{
- case BUILT_IN_CONSTANT_P:
- /* 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. */
- result = integer_zero_node;
- break;
case BUILT_IN_ASSUME_ALIGNED:
/* Remove __builtin_assume_aligned. */