This is the next step in removing forward_propagate_into_comparison and forward_propagate_into_gimple_cond; In the case of `((int)(a cmp b)) != 0` we want to do the transformation to `a cmp b` even if the cast is used twice. This is exactly what forward_propagate_into_comparison/forward_propagate_into_gimple_cond do and does the copy.
Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd (`(a cmp b) != false`, `(a cmp b) == true`, `(a cmp b) != true`, `(a cmp b) == false`): Allow an optional cast between the comparison and the eq/ne. (`bool_val != false`, `bool_val == true`): Allow an optional cast between the bool_val and the ne/eq. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> --- gcc/match.pd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 79485f9678a..ffb1695e6e6 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6913,15 +6913,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (ncmp @0 @1))))) /* The following bits are handled by fold_binary_op_with_conditional_arg. */ (simplify - (ne (cmp@2 @0 @1) integer_zerop) + (ne (convert? (cmp@2 @0 @1)) integer_zerop) (if (types_match (type, TREE_TYPE (@2))) (cmp @0 @1))) (simplify - (eq (cmp@2 @0 @1) integer_truep) + (eq (convert? (cmp@2 @0 @1)) integer_truep) (if (types_match (type, TREE_TYPE (@2))) (cmp @0 @1))) (simplify - (ne (cmp@2 @0 @1) integer_truep) + (ne (convert? (cmp@2 @0 @1)) integer_truep) (if (types_match (type, TREE_TYPE (@2))) (with { enum tree_code ic = invert_tree_comparison (cmp, HONOR_NANS (@0)); } @@ -6930,7 +6930,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (ic == ncmp) (ncmp @0 @1)))))) (simplify - (eq (cmp@2 @0 @1) integer_zerop) + (eq (convert? (cmp@2 @0 @1)) integer_zerop) (if (types_match (type, TREE_TYPE (@2))) (with { enum tree_code ic = invert_tree_comparison (cmp, HONOR_NANS (@0)); } @@ -8104,13 +8104,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* bool_var != 0 becomes bool_var. */ (simplify - (ne @0 integer_zerop) + (ne (convert? @0) integer_zerop) (if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE && types_match (type, TREE_TYPE (@0))) (non_lvalue @0))) /* bool_var == 1 becomes bool_var. */ (simplify - (eq @0 integer_onep) + (eq (convert? @0) integer_onep) (if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE && types_match (type, TREE_TYPE (@0))) (non_lvalue @0))) -- 2.43.0