https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79981
--- Comment #3 from Dominik Vogt <vogt at linux dot vnet.ibm.com> --- (In reply to Richard Biener from comment #2) > of course needs to be conditional on oldlhs being bool and lhs being > integral. Like so? -- diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 9fd45d1..e5e448e 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -3581,7 +3581,12 @@ fold_builtin_atomic_compare_exchange (gimple_stmt_iterator *gsi) } else gsi_insert_after (gsi, g, GSI_NEW_STMT); - g = gimple_build_assign (oldlhs, NOP_EXPR, gimple_assign_lhs (g)); + if (TREE_CODE (TREE_TYPE (oldlhs)) == BOOLEAN_TYPE + && INTEGRAL_TYPE_P (itype)) + g = gimple_build_assign (oldlhs, NE_EXPR, gimple_assign_lhs (g), + build_zero_cst (TREE_TYPE (gimple_assign_lhs (g)))); + else + g = gimple_build_assign (oldlhs, NOP_EXPR, gimple_assign_lhs (g)); gsi_insert_after (gsi, g, GSI_NEW_STMT); } g = gimple_build_assign (make_ssa_name (itype), REALPART_EXPR, -- Lhs has COMPLEX_TYPE, so itype needs to be checked instead, but is it really necessary? Itype comes from the function declaration and should be guaranteed to be of integral type anyway: tree fndecl = gimple_call_fndecl (stmt); tree parmt = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); tree itype = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (parmt))); This eliminates the _Bool and finally results in _8 = IMAGPART_EXPR <_7>; if (_8 != 0) (but not regression tested yet).