[gcc r17-2872] Get rid of ? true : false and simplify ? false : true
Jakub Jelinek via Gcc-cvs <[email protected]> Sat, 1 Aug 2026 09:47:44 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:2f5ed170082f9f2401a0c1c4a18e538c0cf75013 commit r17-2872-g2f5ed170082f9f2401a0c1c4a18e538c0cf75013 Author: Jakub Jelinek <[email protected]> Date: Sat Aug 1 11:46:49 2026 +0200 Get rid of ? true : false and simplify ? false : true Last night I've noticed in match.pd various places like cmp == EQ_EXPR ? true : false and cmp == EQ_EXPR ? false : true I don't think that is useful, neither for readers nor for code formatting. Sure, x ? true : false is not always equivalent to just x, but if it is passed to a bool argument or sets a bool variable or if x is actually a comparison in C++, it is exactly the same. I think using just cmp == EQ_EXPR and cmp != EQ_EXPR is better. 2026-08-01 Jakub Jelinek <[email protected]> * ipa-polymorphic-call.cc (csftc_abort_walking_p): Remove useless "? true : false". * tree-ssa-loop-im.cc (ref_indep_loop_p): Likewise. * match.pd (X ==/!= !X is false/true): Replace "? false : true" with negation of the condition. (((C << x) & D) != 0): Likewise. (fold_sign_changed_comparison and fold_widened_comparison): Likewise. Remove useless "? true : false". (if the second operand is NaN, the result is constant): Replace "? false : true" with negation of the condition. (__builtin_ctz (x) >= C -> (x & ((1 << C) - 1)) == 0): Likewise. Remove useless "? true : false". (__builtin_ctz (x) == C -> (x & ((1 << (C + 1)) - 1)) == (1 << C)): Replace "? false : true" with negation of the condition. (__builtin_ffs (X) == 0 -> X == 0): Remove useless "? true : false". (__builtin_ffs (X) > 6 -> X != 0 && (X & 63) == 0): Likewise. Replace "? false : true" with negation of the condition. * gimple-pretty-print.cc (dump_phi_nodes): Use !(flags & TDF_GIMPLE) instead of (flags & TDF_GIMPLE) ? false : true. gcc/fortran/ * expr.cc (gfc_check_init_expr): Remove useless "? true : false". (gfc_expr_check_typed): Replace "? false : true" with negation of the condition. * parse.cc (gfc_find_state): Likewise. * resolve.cc (impure_stmt_fcn): Likewise. * arith.cc (gfc_check_character_range): Remove useless "? true : false". * array.cc (is_constant_element): Likewise. * decl.cc (gfc_verify_c_interop): Likewise. * interface.cc (gfc_check_dummy_characteristics): Likewise. * io.cc (check_open_constraints): Likewise. (check_close_constraints): Likewise. (check_io_constraints): Likewise. gcc/jit/ * jit-recording.cc (recording::context::set_bool_option): Remove useless "? true : false". Reviewed-by: Andrea Pinski <[email protected]> Diff: --- gcc/fortran/arith.cc | 2 +- gcc/fortran/array.cc | 2 +- gcc/fortran/decl.cc | 3 +-- gcc/fortran/expr.cc | 4 ++-- gcc/fortran/interface.cc | 2 +- gcc/fortran/io.cc | 6 +++--- gcc/fortran/parse.cc | 2 +- gcc/fortran/resolve.cc | 2 +- gcc/gimple-pretty-print.cc | 3 +-- gcc/ipa-polymorphic-call.cc | 2 +- gcc/jit/jit-recording.cc | 4 ++-- gcc/match.pd | 34 +++++++++++++++++----------------- gcc/tree-ssa-loop-im.cc | 2 +- 13 files changed, 33 insertions(+), 35 deletions(-) diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc index 28206bc64b98..de97b27b4454 100644 --- a/gcc/fortran/arith.cc +++ b/gcc/fortran/arith.cc @@ -354,7 +354,7 @@ gfc_check_character_range (gfc_char_t c, int kind) return true; if (kind == 1) - return c <= 255 ? true : false; + return c <= 255; gcc_unreachable (); } diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index 705ff17439bc..733ce5d27d05 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -2118,7 +2118,7 @@ is_constant_element (gfc_expr *e) rv = gfc_is_constant_expr (e); gfc_free_expr (e); - return rv ? true : false; + return rv; } diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 6dad9d9791a4..7c10ee5e5726 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -6592,8 +6592,7 @@ bool gfc_verify_c_interop (gfc_typespec *ts) { if (ts->type == BT_DERIVED && ts->u.derived != NULL) - return (ts->u.derived->ts.is_c_interop || ts->u.derived->attr.is_bind_c) - ? true : false; + return ts->u.derived->ts.is_c_interop || ts->u.derived->attr.is_bind_c; else if (ts->type == BT_CLASS) return false; else if (ts->is_c_interop != 1 && ts->type != BT_ASSUMED) diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index d0f07eec2d44..20eddbefd57d 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -3413,7 +3413,7 @@ gfc_check_init_expr (gfc_expr *e) break; case EXPR_STRUCTURE: - t = e->ts.is_iso_c ? true : false; + t = e->ts.is_iso_c; if (t) break; @@ -6112,7 +6112,7 @@ gfc_expr_check_typed (gfc_expr* e, gfc_namespace* ns, bool strict) check_typed_ns = ns; error_found = gfc_traverse_expr (e, NULL, &expr_check_typed_help, 0); - return error_found ? false : true; + return !error_found; } diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index ccff784a2a5a..9dae6685be2a 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -1398,7 +1398,7 @@ gfc_check_dummy_characteristics (gfc_symbol *s1, gfc_symbol *s2, int err_len) { if (s1 == NULL || s2 == NULL) - return s1 == s2 ? true : false; + return s1 == s2; if (s1->attr.proc == PROC_ST_FUNCTION || s2->attr.proc == PROC_ST_FUNCTION) { diff --git a/gcc/fortran/io.cc b/gcc/fortran/io.cc index 034358e577de..ee73d7c118fc 100644 --- a/gcc/fortran/io.cc +++ b/gcc/fortran/io.cc @@ -2223,7 +2223,7 @@ check_open_constraints (gfc_open *open, locus *where) } \ } - bool warn = (open->err || open->iostat) ? true : false; + bool warn = open->err || open->iostat; /* Checks on the ACCESS specifier. */ if (open->access && open->access->expr_type == EXPR_CONSTANT) @@ -2750,7 +2750,7 @@ cleanup: static bool check_close_constraints (gfc_close *close, locus *where) { - bool warn = (close->iostat || close->err) ? true : false; + bool warn = close->iostat || close->err; if (close->unit == NULL) { @@ -3842,7 +3842,7 @@ if (condition) \ gfc_symbol *sym = NULL; bool warn, unformatted; - warn = (dt->err || dt->iostat) ? true : false; + warn = dt->err || dt->iostat; unformatted = dt->format_expr == NULL && dt->format_label == NULL && dt->namelist == NULL; diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index c5d79bf2fd04..59ef6bb2c2a6 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -2129,7 +2129,7 @@ gfc_find_state (gfc_compile_state state) if (p->state == state) break; - return (p == NULL) ? false : true; + return p != NULL; } diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 389a74516197..94bb3362fe33 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -3292,7 +3292,7 @@ impure_stmt_fcn (gfc_expr *e, gfc_symbol *sym, || e->symtree->n.sym->attr.proc == PROC_ST_FUNCTION) return false; - return gfc_pure_function (e, &name) ? false : true; + return !gfc_pure_function (e, &name); } diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc index 4b88d542a1dd..001865605a15 100644 --- a/gcc/gimple-pretty-print.cc +++ b/gcc/gimple-pretty-print.cc @@ -3023,8 +3023,7 @@ dump_phi_nodes (pretty_printer *pp, basic_block bb, int indent, if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS)) { INDENT (indent); - dump_gimple_phi (pp, phi, indent, - (flags & TDF_GIMPLE) ? false : true, flags); + dump_gimple_phi (pp, phi, indent, !(flags & TDF_GIMPLE), flags); pp_newline (pp); } } diff --git a/gcc/ipa-polymorphic-call.cc b/gcc/ipa-polymorphic-call.cc index b0a1edd96d85..addb52561c70 100644 --- a/gcc/ipa-polymorphic-call.cc +++ b/gcc/ipa-polymorphic-call.cc @@ -1405,7 +1405,7 @@ static inline bool csftc_abort_walking_p (unsigned speculative) { unsigned max = param_max_speculative_devirt_maydefs; - return speculative > max ? true : false; + return speculative > max; } /* Callback of walk_aliased_vdefs and a helper function for diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc index 07c82cc1b4fd..e28e5f67cd8d 100644 --- a/gcc/jit/jit-recording.cc +++ b/gcc/jit/jit-recording.cc @@ -1546,7 +1546,7 @@ recording::context::set_bool_option (enum gcc_jit_bool_option opt, "unrecognized (enum gcc_jit_bool_option) value: %i", opt); return; } - m_bool_options[opt] = value ? true : false; + m_bool_options[opt] = value; log_bool_option (opt); } @@ -1555,7 +1555,7 @@ recording::context::set_inner_bool_option (enum inner_bool_option inner_opt, int value) { gcc_assert (inner_opt >= 0 && inner_opt < NUM_INNER_BOOL_OPTIONS); - m_inner_bool_options[inner_opt] = value ? true : false; + m_inner_bool_options[inner_opt] = value; log_inner_bool_option (inner_opt); } diff --git a/gcc/match.pd b/gcc/match.pd index 2541b898d2e6..b757aaf6f695 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2522,7 +2522,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for op (bit_ior bit_xor eq ne) (simplify (op:c truth_valued_p@0 (logical_inverted_value @0)) - { constant_boolean_node (op == EQ_EXPR ? false : true, type); })) + { constant_boolean_node (op != EQ_EXPR, type); })) /* ~~x -> x */ (simplify @@ -5289,7 +5289,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) than D. See PR126476. */ || !wi::fits_to_tree_p (wi::shwi (c1 - c2, HOST_BITS_PER_INT), TREE_TYPE (@0))) - { constant_boolean_node (cmp == NE_EXPR ? false : true, type); } + { constant_boolean_node (cmp != NE_EXPR, type); } (icmp @0 { build_int_cst (TREE_TYPE (@0), c1 - c2); })))) (simplify (cmp (bit_and (rshift integer_pow2p@1 @0) integer_pow2p@2) integer_zerop) @@ -5299,7 +5299,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (c1 > c2 || !wi::fits_to_tree_p (wi::shwi (c2 - c1, HOST_BITS_PER_INT), TREE_TYPE (@0))) - { constant_boolean_node (cmp == NE_EXPR ? false : true, type); } + { constant_boolean_node (cmp != NE_EXPR, type); } (icmp @0 { build_int_cst (TREE_TYPE (@0), c2 - c1); })))))) /* (CST1 << A) == CST2 -> A == ctz (CST2) - ctz (CST1) @@ -8104,11 +8104,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (if (above || below) (if (cmp == EQ_EXPR || cmp == NE_EXPR) - { constant_boolean_node (cmp == EQ_EXPR ? false : true, type); } + { constant_boolean_node (cmp != EQ_EXPR, type); } (if (cmp == LT_EXPR || cmp == LE_EXPR) - { constant_boolean_node (above ? true : false, type); } + { constant_boolean_node (above, type); } (if (cmp == GT_EXPR || cmp == GE_EXPR) - { constant_boolean_node (above ? false : true, type); }))))))) + { constant_boolean_node (!above, type); }))))))) /* For eq/ne with narrowing conversion: (T)(X) == (T)(Y) -> (T)(X ^ Y) == 0 */ @@ -8584,8 +8584,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp @0 REAL_CST@1) (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1)) && (cmp != LTGT_EXPR || ! flag_trapping_math)) - { constant_boolean_node (cmp == ORDERED_EXPR || cmp == LTGT_EXPR - ? false : true, type); }))) + { constant_boolean_node (cmp != ORDERED_EXPR && cmp != LTGT_EXPR, + type); }))) /* Fold UNORDERED if either operand must be NaN, or neither can be. */ (simplify @@ -10535,9 +10535,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (if (ok && prec <= MAX_FIXED_MODE_SIZE) (if (val <= 0) - { constant_boolean_node (cmp == EQ_EXPR ? true : false, type); } + { constant_boolean_node (cmp == EQ_EXPR, type); } (if (val >= prec) - { constant_boolean_node (cmp == EQ_EXPR ? false : true, type); } + { constant_boolean_node (cmp != EQ_EXPR, type); } (cmp (bit_and @0 { wide_int_to_tree (type0, wi::mask (val, false, prec)); }) { build_zero_cst (type0); }))))))) @@ -10557,7 +10557,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (if (ok && prec <= MAX_FIXED_MODE_SIZE) (if (tree_int_cst_sgn (@1) < 0 || wi::to_widest (@1) >= prec) - { constant_boolean_node (op == EQ_EXPR ? false : true, type); } + { constant_boolean_node (op != EQ_EXPR, type); } (op (bit_and @0 { wide_int_to_tree (type0, wi::mask (tree_to_uhwi (@1) + 1, false, prec)); }) @@ -10593,10 +10593,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (if (val <= 0) (if (ok && zero_val >= val) - { constant_boolean_node (cmp == EQ_EXPR ? true : false, type); }) + { constant_boolean_node (cmp == EQ_EXPR, type); }) (if (val >= prec) (if (ok && zero_val < val) - { constant_boolean_node (cmp == EQ_EXPR ? false : true, type); }) + { constant_boolean_node (cmp != EQ_EXPR, type); }) (if (ok && (zero_val < 0 || zero_val >= prec)) (cmp (bit_and @0 { wide_int_to_tree (type0, wi::mask (val, false, prec)); }) @@ -10612,7 +10612,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (prec <= MAX_FIXED_MODE_SIZE) (if (tree_int_cst_sgn (@1) < 0 || wi::to_widest (@1) >= prec) (if (zero_val != wi::to_widest (@1)) - { constant_boolean_node (op == EQ_EXPR ? false : true, type); }) + { constant_boolean_node (op != EQ_EXPR, type); }) (if (zero_val < 0 || zero_val >= prec) (op (bit_and @0 { wide_int_to_tree (type0, wi::mask (tree_to_uhwi (@1) + 1, @@ -11284,7 +11284,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (integer_zerop (@1)) (cmp @0 { build_zero_cst (TREE_TYPE (@0)); })) (if (tree_int_cst_sgn (@1) < 0 || wi::to_widest (@1) > prec) - { constant_boolean_node (cmp == NE_EXPR ? true : false, type); }) + { constant_boolean_node (cmp == NE_EXPR, type); }) (if (single_use (@2)) (cmp (bit_and @0 { wide_int_to_tree (TREE_TYPE (@0), wi::mask (tree_to_uhwi (@1), @@ -11305,9 +11305,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (integer_zerop (@1)) (cmp2 @0 { build_zero_cst (TREE_TYPE (@0)); })) (if (tree_int_cst_sgn (@1) < 0) - { constant_boolean_node (cmp == GT_EXPR ? true : false, type); }) + { constant_boolean_node (cmp == GT_EXPR, type); }) (if (wi::to_widest (@1) >= prec) - { constant_boolean_node (cmp == GT_EXPR ? false : true, type); }) + { constant_boolean_node (cmp != GT_EXPR, type); }) (if (wi::to_widest (@1) == prec - 1) (cmp3 @0 { wide_int_to_tree (TREE_TYPE (@0), wi::shifted_mask (prec - 1, 1, diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index 592a37da5dc7..412645600093 100644 --- a/gcc/tree-ssa-loop-im.cc +++ b/gcc/tree-ssa-loop-im.cc @@ -3257,7 +3257,7 @@ ref_indep_loop_p (class loop *loop, im_mem_ref *ref, dep_kind kind) /* tri-state, { unknown, independent, dependent } */ dep_state state = query_loop_dependence (loop, ref, kind); if (state != dep_unknown) - return state == dep_independent ? true : false; + return state == dep_independent; class loop *inner = loop->inner; while (inner)