From: Martin Liska Date: Mon, 16 Sep 2019 14:23:04 +0000 (+0200) Subject: Rewrite second part of or_comparisons_1 into match.pd. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cda65821d3c398f5ad969ca1de71e8cd70c58e55;p=gcc.git Rewrite second part of or_comparisons_1 into match.pd. 2019-09-16 Martin Liska * gimple-fold.c (or_comparisons_1): Remove rules moved to ... * match.pd: ... here. From-SVN: r275752 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e70e09070c9..1921bc775d6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-09-16 Martin Liska + + * gimple-fold.c (or_comparisons_1): Remove rules moved + to ... + * match.pd: ... here. + 2019-09-16 Martin Liska * gimple-fold.c (or_comparisons_1): Remove rules diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 694d2eeaae6..8d642de2f67 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6042,51 +6042,6 @@ or_comparisons_1 (tree type, enum tree_code code1, tree op1a, tree op1b, return t; } - /* If both comparisons are of the same value against constants, we might - be able to merge them. */ - if (operand_equal_p (op1a, op2a, 0) - && TREE_CODE (op1b) == INTEGER_CST - && TREE_CODE (op2b) == INTEGER_CST) - { - int cmp = tree_int_cst_compare (op1b, op2b); - - /* Chose the less restrictive of two < or <= comparisons. */ - if ((code1 == LT_EXPR || code1 == LE_EXPR) - && (code2 == LT_EXPR || code2 == LE_EXPR)) - { - if ((cmp < 0) || (cmp == 0 && code1 == LT_EXPR)) - return fold_build2 (code2, boolean_type_node, op2a, op2b); - else - return fold_build2 (code1, boolean_type_node, op1a, op1b); - } - - /* Likewise chose the less restrictive of two > or >= comparisons. */ - else if ((code1 == GT_EXPR || code1 == GE_EXPR) - && (code2 == GT_EXPR || code2 == GE_EXPR)) - { - if ((cmp > 0) || (cmp == 0 && code1 == GT_EXPR)) - return fold_build2 (code2, boolean_type_node, op2a, op2b); - else - return fold_build2 (code1, boolean_type_node, op1a, op1b); - } - - /* Check for singleton ranges. */ - else if (cmp == 0 - && ((code1 == LT_EXPR && code2 == GT_EXPR) - || (code1 == GT_EXPR && code2 == LT_EXPR))) - return fold_build2 (NE_EXPR, boolean_type_node, op1a, op2b); - - /* Check for less/greater pairs that don't restrict the range at all. */ - else if (cmp >= 0 - && (code1 == LT_EXPR || code1 == LE_EXPR) - && (code2 == GT_EXPR || code2 == GE_EXPR)) - return boolean_true_node; - else if (cmp <= 0 - && (code1 == GT_EXPR || code1 == GE_EXPR) - && (code2 == LT_EXPR || code2 == LE_EXPR)) - return boolean_true_node; - } - /* Perhaps the first comparison is (NAME != 0) or (NAME == 1) where NAME's definition is a truth value. See if there are any simplifications that can be done against the NAME's definition. */ diff --git a/gcc/match.pd b/gcc/match.pd index c465eabbb89..4fd7590cc39 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2051,6 +2051,44 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (code1 == NE_EXPR && val) { constant_boolean_node (true, type); }) (if (code1 == NE_EXPR && !val) @3)))))) +/* Convert (X OP1 CST1) || (X OP2 CST2). */ + +(for code1 (lt le gt ge) + (for code2 (lt le gt ge) + (simplify + (bit_ior (code1@3 @0 INTEGER_CST@1) (code2@4 @0 INTEGER_CST@2)) + (with + { + int cmp = tree_int_cst_compare (@1, @2); + } + (switch + /* Choose the more restrictive of two < or <= comparisons. */ + (if ((code1 == LT_EXPR || code1 == LE_EXPR) + && (code2 == LT_EXPR || code2 == LE_EXPR)) + (if ((cmp < 0) || (cmp == 0 && code1 == LT_EXPR)) + @4 + @3)) + /* Likewise chose the more restrictive of two > or >= comparisons. */ + (if ((code1 == GT_EXPR || code1 == GE_EXPR) + && (code2 == GT_EXPR || code2 == GE_EXPR)) + (if ((cmp > 0) || (cmp == 0 && code1 == GT_EXPR)) + @4 + @3)) + /* Check for singleton ranges. */ + (if (cmp == 0 + && ((code1 == LT_EXPR && code2 == GT_EXPR) + || (code1 == GT_EXPR && code2 == LT_EXPR))) + (ne @0 @2)) + /* Check for disjoint ranges. */ + (if (cmp >= 0 + && (code1 == LT_EXPR || code1 == LE_EXPR) + && (code2 == GT_EXPR || code2 == GE_EXPR)) + { constant_boolean_node (true, type); }) + (if (cmp <= 0 + && (code1 == GT_EXPR || code1 == GE_EXPR) + && (code2 == LT_EXPR || code2 == LE_EXPR)) + { constant_boolean_node (true, type); }) + ))))) /* We can't reassociate at all for saturating types. */ (if (!TYPE_SATURATING (type))