From 9707b593f88041e74e5cf5640ec64fea13a0387c Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Tue, 14 Apr 2020 19:26:04 +0200 Subject: [PATCH] ipa-sra: Fix treatment of internal functions (PR 94434) IPA-SRA can segfault when processing a call to an internal function because such calls do not have corresponding call graphs and should be treated like memory accesses anyway, which what the patch below does. The patch makes an attempt to differentiate between reads and writes, although for things passed by value it does not make any difference. It treats all arguments of functions denoted with internal_store_fn_p as written to, even though in practice only some are, but for IPA-SRA purposes, actions needed to be taken when processing a read are also always performed when analyzing a write, so the code is just slightly pessimistic. But not as pessimistic as bailing out on any internal call immediately. I have LTO bootstrapped and tested the patch on x86_64-linux and normally bootstrapped and tested it on aarch64-linux, although one which is not SVE capable. I would appreciate testing on such machine too - as well as a small testcase that would follow all relevant conventions in gcc.target/aarch64/sve. 2020-04-14 Martin Jambor PR ipa/94434 * ipa-sra.c: Include internal-fn.h. (enum isra_scan_context): Update comment. (scan_function): Treat calls to internal_functions like loads or stores. --- gcc/ChangeLog | 7 +++++++ gcc/ipa-sra.c | 26 ++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 441dcab..483bd85 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2020-04-14 Martin Jambor + + PR ipa/94434 + * ipa-sra.c: Include internal-fn.h. + (enum isra_scan_context): Update comment. + (scan_function): Treat calls to internal_functions like loads or stores. + 2020-04-14 Yang Yang PR tree-optimization/94574 diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c index f0ebaec..7c922e4 100644 --- a/gcc/ipa-sra.c +++ b/gcc/ipa-sra.c @@ -83,7 +83,7 @@ along with GCC; see the file COPYING3. If not see #include "builtins.h" #include "cfganal.h" #include "tree-streamer.h" - +#include "internal-fn.h" /* Bits used to track size of an aggregate in bytes interprocedurally. */ #define ISRA_ARG_SIZE_LIMIT_BITS 16 @@ -1281,7 +1281,9 @@ allocate_access (gensum_param_desc *desc, } /* In what context scan_expr_access has been called, whether it deals with a - load, a function argument, or a store. */ + load, a function argument, or a store. Please note that in rare + circumstances when it is not clear if the access is a load or store, + ISRA_CTX_STORE is used too. */ enum isra_scan_context {ISRA_CTX_LOAD, ISRA_CTX_ARG, ISRA_CTX_STORE}; @@ -1870,15 +1872,27 @@ scan_function (cgraph_node *node, struct function *fun) case GIMPLE_CALL: { unsigned argument_count = gimple_call_num_args (stmt); - scan_call_info call_info; - call_info.cs = node->get_edge (stmt); - call_info.argument_count = argument_count; + isra_scan_context ctx = ISRA_CTX_ARG; + scan_call_info call_info, *call_info_p = &call_info; + if (gimple_call_internal_p (stmt)) + { + call_info_p = NULL; + ctx = ISRA_CTX_LOAD; + internal_fn ifn = gimple_call_internal_fn (stmt); + if (internal_store_fn_p (ifn)) + ctx = ISRA_CTX_STORE; + } + else + { + call_info.cs = node->get_edge (stmt); + call_info.argument_count = argument_count; + } for (unsigned i = 0; i < argument_count; i++) { call_info.arg_idx = i; scan_expr_access (gimple_call_arg (stmt, i), stmt, - ISRA_CTX_ARG, bb, &call_info); + ctx, bb, call_info_p); } tree lhs = gimple_call_lhs (stmt); -- 2.7.4