From 20805fb54aee0d0e337d53facf77a5c66f9f0c9c 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 | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/gcc/gimple-range-infer.cc b/gcc/gimple-range-infer.cc index f0d66d047a6..95839445155 100644 --- a/gcc/gimple-range-infer.cc +++ b/gcc/gimple-range-infer.cc @@ -36,6 +36,25 @@ along with GCC; see the file COPYING3. If not see #include "gimple-walk.h" #include "cfganal.h" + +// This routine needs to be provided to look up any ASSUME values +// for name in ASSUME_ID. Return TRUE if it has a value. + +bool +query_assume_call (vrange &r, tree assume_id, tree name) +{ + if (dump_file) + fprintf (dump_file, "query_assume_call injection\n"); + if (assume_id != NULL_TREE) + { + // Just return the global value until this can be provided. + gimple_range_global (r, name); + return true; + } + return false; +} + + // Adapted from infer_nonnull_range_by_dereference and check_loadstore // to process nonnull ssa_name OP in S. DATA contains a pointer to a // stmt range inference instance. @@ -111,6 +130,35 @@ 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 assume_id = gimple_call_arg (s, 0); + for (unsigned i = 1; i < gimple_call_num_args (s); i++) + { + tree op = gimple_call_arg (s, i); + tree type = TREE_TYPE (op); + if (gimple_range_ssa_p (op) && Value_Range::supports_type_p (type)) + { + Value_Range assume_range (type); + if (query_assume_call (assume_range, assume_id, op)) + { + 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, " to "); + 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