public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3325] openmp: Improve expand_omp_atomic_pipeline Date: Fri, 3 Sep 2021 07:58:20 +0000 (GMT) [thread overview] Message-ID: <20210903075820.C5D9E3864840@sourceware.org> (raw) https://gcc.gnu.org/g:090f0d78f194e3cda23fe904016db77ea36c38fa commit r12-3325-g090f0d78f194e3cda23fe904016db77ea36c38fa Author: Jakub Jelinek <jakub@redhat.com> Date: Fri Sep 3 09:54:58 2021 +0200 openmp: Improve expand_omp_atomic_pipeline When __atomic_* builtins were introduced, omp-expand.c (omp-low.c at that point) has been adjusted in several spots so that it uses the atomic builtins instead of sync builtins, but expand_omp_atomic_pipeline has not because the __atomic_compare_exchange_* APIs take address of the argument, so it kept using __sync_val_compare_swap_*. That means it always uses seq_cst though. This patch changes it to use the ATOMIC_COMPARE_EXCHANGE ifn which gimple-fold folds __atomic_compare_exchange_* into - that ifn also passes expected directly. 2021-09-03 Jakub Jelinek <jakub@redhat.com> * omp-expand.c (expand_omp_atomic_pipeline): Use IFN_ATOMIC_COMPARE_EXCHANGE instead of BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_? so that memory order can be provided. Diff: --- gcc/omp-expand.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c index a0e9e61b33e..f2b6f6fa6a6 100644 --- a/gcc/omp-expand.c +++ b/gcc/omp-expand.c @@ -8807,8 +8807,6 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb, edge e; enum built_in_function fncode; - /* ??? We need a non-pointer interface to __atomic_compare_exchange in - order to use the RELAXED memory model effectively. */ fncode = (enum built_in_function)((int)BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N + index + 1); cmpxchg = builtin_decl_explicit (fncode); @@ -8825,6 +8823,15 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb, /* Load the initial value, replacing the GIMPLE_OMP_ATOMIC_LOAD. */ si = gsi_last_nondebug_bb (load_bb); gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_LOAD); + location_t loc = gimple_location (gsi_stmt (si)); + enum omp_memory_order omo = gimple_omp_atomic_memory_order (gsi_stmt (si)); + enum memmodel imo = omp_memory_order_to_memmodel (omo); + tree mo = build_int_cst (NULL, imo); + if (imo == MEMMODEL_RELEASE) + imo = MEMMODEL_RELAXED; + else if (imo == MEMMODEL_ACQ_REL) + imo = MEMMODEL_ACQUIRE; + tree fmo = build_int_cst (NULL, imo); /* For floating-point values, we'll need to view-convert them to integers so that we can perform the atomic compare and swap. Simplify the @@ -8921,7 +8928,15 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb, GSI_SAME_STMT); /* Build the compare&swap statement. */ - new_storedi = build_call_expr (cmpxchg, 3, iaddr, loadedi, storedi); + tree ctype = build_complex_type (itype); + int flag = int_size_in_bytes (itype); + new_storedi = build_call_expr_internal_loc (loc, IFN_ATOMIC_COMPARE_EXCHANGE, + ctype, 6, iaddr, loadedi, + storedi, + build_int_cst (integer_type_node, + flag), + mo, fmo); + new_storedi = build1 (REALPART_EXPR, itype, new_storedi); new_storedi = force_gimple_operand_gsi (&si, fold_convert (TREE_TYPE (loadedi), new_storedi),
reply other threads:[~2021-09-03 7:58 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210903075820.C5D9E3864840@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).