From a252bbd11d22481a1e719ed36d800e2192abb369 Mon Sep 17 00:00:00 2001 From: Pronin Alexander Date: Thu, 31 Oct 2024 15:49:27 +0800 Subject: [PATCH 1/6] Mark prefetch builtin as willreturn Signed-off-by: Pronin Alexander --- gcc/common.opt | 4 ++++ gcc/gimple.cc | 30 ++++++++++++++++++++++++++++++ gcc/gimple.h | 1 + gcc/tree-ssa-pre.cc | 4 +--- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 688d65e4d..be5fcc681 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1313,6 +1313,10 @@ fdelete-null-pointer-checks Common Var(flag_delete_null_pointer_checks) Init(-1) Optimization Delete useless null pointer checks. +fbuiltin-will-return +Common Var(flag_builtin_will_return) Optimization +Consider some of the builtins as definitely returning. + fdevirtualize-at-ltrans Common Var(flag_ltrans_devirtualize) Stream extra data to support more aggressive devirtualization in LTO local transformation mode. diff --git a/gcc/gimple.cc b/gcc/gimple.cc index 9e62da426..04ca9f161 100644 --- a/gcc/gimple.cc +++ b/gcc/gimple.cc @@ -2998,6 +2998,36 @@ nonbarrier_call_p (gimple *call) return false; } +static inline bool +will_return_builtin_p (gimple *call) +{ + if (!flag_builtin_will_return) + return false; + + if (!gimple_call_builtin_p (call, BUILT_IN_NORMAL)) + return false; + + switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call))) + { + case BUILT_IN_PREFETCH: + return true; + default: + return false; + } +} + +bool +will_return_call_p (gimple *call, function *fun) +{ + int flags = gimple_call_flags (call); + if (!(flags & (ECF_CONST|ECF_PURE)) + || (flags & ECF_LOOPING_CONST_OR_PURE) + || stmt_can_throw_external (fun, call)) + return will_return_builtin_p (call); + + return true; +} + /* Callback for walk_stmt_load_store_ops. Return TRUE if OP will dereference the tree stored in DATA, FALSE diff --git a/gcc/gimple.h b/gcc/gimple.h index 77a5a07e9..bb05a7664 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -1628,6 +1628,7 @@ extern bool gimple_asm_clobbers_memory_p (const gasm *); extern void dump_decl_set (FILE *, bitmap); extern bool nonfreeing_call_p (gimple *); extern bool nonbarrier_call_p (gimple *); +extern bool will_return_call_p (gimple *, function *); extern bool infer_nonnull_range (gimple *, tree); extern bool infer_nonnull_range_by_dereference (gimple *, tree); extern bool infer_nonnull_range_by_attribute (gimple *, tree); diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index 98134b5d3..b5264133a 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -3988,9 +3988,7 @@ compute_avail (function *fun) that forbids hoisting possibly trapping expressions before it. */ int flags = gimple_call_flags (stmt); - if (!(flags & (ECF_CONST|ECF_PURE)) - || (flags & ECF_LOOPING_CONST_OR_PURE) - || stmt_can_throw_external (fun, stmt)) + if (!will_return_call_p (stmt, fun)) /* Defer setting of BB_MAY_NOTRETURN to avoid it influencing the processing of the call itself. */ set_bb_may_notreturn = true; -- 2.33.0