From 62cc63ca8d5cce3593cdb4b35e5fe96b0ecc77a8 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 18 Oct 2022 16:29:49 -0400 Subject: [PATCH 1/3] Infer support --- gcc/gimple-range-infer.cc | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gcc/gimple-range-infer.cc b/gcc/gimple-range-infer.cc index f0d66d047a6..3e376740796 100644 --- a/gcc/gimple-range-infer.cc +++ b/gcc/gimple-range-infer.cc @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-iterator.h" #include "gimple-walk.h" #include "cfganal.h" +#include "tree-dfa.h" // Adapted from infer_nonnull_range_by_dereference and check_loadstore // to process nonnull ssa_name OP in S. DATA contains a pointer to a @@ -111,6 +112,45 @@ gimple_infer_range::gimple_infer_range (gimple *s) // Fallthru and walk load/store ops now. } + // Look for ASSUME calls, and call query_assume_call for each argument + // to determine if there is any inferred range to be had. + if (is_a (s) && gimple_call_internal_p (s) + && gimple_call_internal_fn (s) == IFN_ASSUME) + { + tree arg; + unsigned i; + tree assume_id = TREE_OPERAND (gimple_call_arg (s, 0), 0); + struct function *fun = DECL_STRUCT_FUNCTION (assume_id); + for (arg = DECL_ARGUMENTS (assume_id), i = 1; + arg && i < gimple_call_num_args (s); + i++, arg = DECL_CHAIN (arg)) + { + tree op = gimple_call_arg (s, i); + tree type = TREE_TYPE (op); + tree def = ssa_default_def (fun, arg); + if (type != TREE_TYPE (arg) || !def) + continue; + if (gimple_range_ssa_p (op) && Value_Range::supports_type_p (type)) + { + Value_Range assume_range (type); + global_ranges.range_of_expr (assume_range, def); + { + add_range (op, assume_range); + if (dump_file) + { + print_generic_expr (dump_file, assume_id, TDF_SLIM); + fprintf (dump_file, " assume inferred range of "); + print_generic_expr (dump_file, op, TDF_SLIM); + fprintf (dump_file, " (param "); + print_generic_expr (dump_file, arg, TDF_SLIM); + fprintf (dump_file, ") = "); + assume_range.dump (dump_file); + fputc ('\n', dump_file); + } + } + } + } + } // Look for possible non-null values. if (flag_delete_null_pointer_checks && gimple_code (s) != GIMPLE_ASM && !gimple_clobber_p (s)) -- 2.37.3