From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 072403864824 for ; Fri, 3 Sep 2021 08:02:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 072403864824 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-503-KaG9e5zdONurk7ZqUpk1Iw-1; Fri, 03 Sep 2021 04:02:37 -0400 X-MC-Unique: KaG9e5zdONurk7ZqUpk1Iw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D0B4802B4F for ; Fri, 3 Sep 2021 08:02:36 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F13F477718 for ; Fri, 3 Sep 2021 08:02:35 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 18382XFf4081366 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Fri, 3 Sep 2021 10:02:34 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 18382VtV4081365 for gcc-patches@gcc.gnu.org; Fri, 3 Sep 2021 10:02:31 +0200 Date: Fri, 3 Sep 2021 10:02:31 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Improve expand_omp_atomic_pipeline Message-ID: <20210903080231.GW920497@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Sep 2021 08:02:40 -0000 Hi! 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. Bootstrapped/regtested on x86_64-linux, committed to trunk. 2021-09-03 Jakub Jelinek * 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. --- gcc/omp-expand.c.jj 2021-09-01 11:37:41.966556334 +0200 +++ gcc/omp-expand.c 2021-09-02 15:50:58.276341091 +0200 @@ -8807,8 +8807,6 @@ expand_omp_atomic_pipeline (basic_block 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 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 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), Jakub