From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 868C73858436; Thu, 8 Sep 2022 12:25:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 868C73858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662639934; bh=1EcYP3om3hXe+X4Y3STReLsJvdbM8SGzZubkXFax6U0=; h=From:To:Subject:Date:From; b=xFNuTPdsRTgcZDYQqZ/lsJfMm7LJb7SsNQ0dLJPb9gifqSNjsJNsnmxEQa9t3A+V+ VhqAPdBhw2MB316NvpTwfKHIhAVhk/1j+i5hXM3imE5+/wHQOKaNcR4oH4B3gZasEP dQ1W8BU8faaJirs8WGFdPSh5AtP0ZeCidU+nVbkQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] Fix OMP CAS expansion with separate condition X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: b52d3705e27a5ca62ffaeda867392cbf417b0082 X-Git-Newrev: 6fb06f2628352da3ecf6649a66a1444b598caf59 Message-Id: <20220908122534.868C73858436@sourceware.org> Date: Thu, 8 Sep 2022 12:25:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6fb06f2628352da3ecf6649a66a1444b598caf59 commit 6fb06f2628352da3ecf6649a66a1444b598caf59 Author: Richard Biener Date: Thu Sep 8 14:24:32 2022 +0200 Fix OMP CAS expansion with separate condition 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. 2022-05-13 Richard Biener * omp-expand.cc (expand_omp_atomic_cas): Do not short-cut computation of the new value. (cherry picked from commit 060173dd73fcaf0767215f9d989ad064e2d5fe2a) Diff: --- gcc/ChangeLog.omp | 8 ++++++++ gcc/omp-expand.cc | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index f7a0a77780e..ae066d893cc 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-09-08 Tobias Burnus + + Backport from mainline: + 2022-05-13 Richard Biener + + * omp-expand.cc (expand_omp_atomic_cas): Do not short-cut + computation of the new value. + 2022-09-08 Tobias Burnus Backport from mainline: diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index fa7d3649c83..f2fd0ee9e90 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -9283,16 +9283,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);