summaryrefslogtreecommitdiffstats
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-05-13 12:07:58 +0200
committerRichard Biener <rguenther@suse.de>2022-05-19 16:25:55 +0200
commit060173dd73fcaf0767215f9d989ad064e2d5fe2a (patch)
tree6aa51bd15b5f5e04d5f7c65ac65499119665799b /gcc
parentRemove get_or_alloc_expression_id (diff)
downloadgcc-060173dd73fcaf0767215f9d989ad064e2d5fe2a.tar.gz
gcc-060173dd73fcaf0767215f9d989ad064e2d5fe2a.tar.bz2
gcc-060173dd73fcaf0767215f9d989ad064e2d5fe2a.tar.xz
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 <rguenther@suse.de> * omp-expand.cc (expand_omp_atomic_cas): Do not short-cut computation of the new value.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/omp-expand.cc11
1 files 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,
9092 9092
9093 if (cond_stmt) 9093 if (cond_stmt)
9094 { 9094 {
9095 g = gimple_build_assign (gimple_assign_lhs (cond_stmt), 9095 g = gimple_build_assign (cond, NOP_EXPR, im);
9096 NOP_EXPR, im);
9097 gimple_set_location (g, loc); 9096 gimple_set_location (g, loc);
9098 gsi_insert_before (&gsi, g, GSI_SAME_STMT); 9097 gsi_insert_before (&gsi, g, GSI_SAME_STMT);
9099 } 9098 }
9100 else if (need_new) 9099
9100 if (need_new)
9101 { 9101 {
9102 g = gimple_build_assign (create_tmp_reg (itype), COND_EXPR, 9102 g = gimple_build_assign (create_tmp_reg (itype), COND_EXPR,
9103 build2 (NE_EXPR, boolean_type_node, 9103 cond_stmt
9104 im, build_zero_cst (itype)), 9104 ? cond : build2 (NE_EXPR, boolean_type_node,
9105 im, build_zero_cst (itype)),
9105 d, re); 9106 d, re);
9106 gimple_set_location (g, loc); 9107 gimple_set_location (g, loc);
9107 gsi_insert_before (&gsi, g, GSI_SAME_STMT); 9108 gsi_insert_before (&gsi, g, GSI_SAME_STMT);