From patchwork Fri May 13 10:23:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 53921 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4CE4A3838006 for ; Fri, 13 May 2022 10:23:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CE4A3838006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652437412; bh=oesUI+DmzlJw3qxzS0vvX4VtbOq5ZJUDJOGrnd7/Lp8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=MGRFa1hj6MovSL4HoifQLCkX+SGA3AcIE/OogvoIB4zv2BHt22vQ022YxFnwxXyW1 0neG+tveDpmi9zxN3G+UiUgsx73Ej+unQgISa6ftL0ZV+JeXk5MZlAuxrmKG7hQL+q O+hv/tCbCingyZb4gl4y4YKvV1ykyzFlkzymjPG4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 4453B3839C47 for ; Fri, 13 May 2022 10:23:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4453B3839C47 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 370A421AA8; Fri, 13 May 2022 10:23:02 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1FBE213446; Fri, 13 May 2022 10:23:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2YGdBoYxfmJMGQAAMHmgww (envelope-from ); Fri, 13 May 2022 10:23:02 +0000 Date: Fri, 13 May 2022 12:23:01 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix OMP CAS expansion with separate condition MIME-Version: 1.0 Message-Id: <20220513102302.1FBE213446@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When forcing the condition to be split out from COND_EXPRs I see a runtime failure of libgomp.fortran/atomic-19.f90 which can be reduced to !$omp atomic update, compare, capture if (x == 69_2 - r) x = 6_8 v = x being miscompiled, the difference being - _13 = .ATOMIC_COMPARE_EXCHANGE (_9, _10, _11, 4, 0, 0); - _14 = IMAGPART_EXPR <_13>; - _15 = REALPART_EXPR <_13>; - _16 = _14 != 0 ? _11 : _15; - _2 = (integer(kind=4)) _16; - v_17 = _2; + _14 = .ATOMIC_COMPARE_EXCHANGE (_10, _11, _12, 4, 0, 0); + _15 = IMAGPART_EXPR <_14>; + _16 = REALPART_EXPR <_14>; + _2 = (logical(kind=1)) _15; + _3 = (integer(kind=4)) _16; + v_17 = _3; where one can see a missing COND_EXPR. It seems to be a latent issue to me given the code can be exercised, it just maybe misses a 'need_new' testcase combined with 'cond_stmt'. Appearantly the if (cond_stmt) code is just to avoid creating a temporary (and possibly to preserve the condition compute if used elsewhere since the original stmt is going to be deleted). The following makes the failure go away for me in my patched tree and it also survives libgomp and gomp testing in an unpatched tree. Full bootstrap & regtest running on x86_64-unknown-linux-gnu. OK? Thanks, Richard. 2022-05-13 Richard Biener * omp-expand.cc (expand_omp_atomic_cas): Do not short-cut computation of the new value. --- gcc/omp-expand.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index ee708314793..9fcc67a3448 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -9092,16 +9092,17 @@ expand_omp_atomic_cas (basic_block load_bb, tree addr, if (cond_stmt) { - g = gimple_build_assign (gimple_assign_lhs (cond_stmt), - NOP_EXPR, im); + g = gimple_build_assign (cond, NOP_EXPR, im); gimple_set_location (g, loc); gsi_insert_before (&gsi, g, GSI_SAME_STMT); } - else if (need_new) + + if (need_new) { g = gimple_build_assign (create_tmp_reg (itype), COND_EXPR, - build2 (NE_EXPR, boolean_type_node, - im, build_zero_cst (itype)), + cond_stmt + ? cond : build2 (NE_EXPR, boolean_type_node, + im, build_zero_cst (itype)), d, re); gimple_set_location (g, loc); gsi_insert_before (&gsi, g, GSI_SAME_STMT);