diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-05-04 11:03:32 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-05-04 11:03:32 +0200 |
commit | 6b5c7ee0df6b87780f2fd6f2c5759a04e6eed1fe (patch) | |
tree | ad20e71284b9b89bbcf272c547c50ab0d8c754f9 /gcc/match.pd | |
parent | 496f4f884716ae061f771a62e44868a32dbd502f (diff) |
match.pd: Optimize (x < 0) != (y < 0) into (x ^ y) < 0 [PR94718]
The following patch (on top of the two other PR94718 patches) performs the
actual optimization requested in the PR.
2020-05-04 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/94718
* match.pd ((X < 0) != (Y < 0) into (X ^ Y) < 0): New simplification.
* gcc.dg/tree-ssa/pr94718-4.c: New test.
* gcc.dg/tree-ssa/pr94718-5.c: New test.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index 929be14e8b7..9c1e23984d6 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4358,6 +4358,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp (bit_and:cs @0 @2) (bit_and:cs @1 @2)) (cmp (bit_and (bit_xor @0 @1) @2) { build_zero_cst (TREE_TYPE (@2)); }))) +/* (X < 0) != (Y < 0) into (X ^ Y) < 0. + (X >= 0) != (Y >= 0) into (X ^ Y) < 0. + (X < 0) == (Y < 0) into (X ^ Y) >= 0. + (X >= 0) == (Y >= 0) into (X ^ Y) >= 0. */ +(for cmp (eq ne) + ncmp (ge lt) + (for sgncmp (ge lt) + (simplify + (cmp (sgncmp @0 integer_zerop@2) (sgncmp @1 integer_zerop)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && !TYPE_UNSIGNED (TREE_TYPE (@0)) + && types_match (@0, @1)) + (ncmp (bit_xor @0 @1) @2))))) +/* (X < 0) == (Y >= 0) into (X ^ Y) < 0. + (X < 0) != (Y >= 0) into (X ^ Y) >= 0. */ +(for cmp (eq ne) + ncmp (lt ge) + (simplify + (cmp:c (lt @0 integer_zerop@2) (ge @1 integer_zerop)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && !TYPE_UNSIGNED (TREE_TYPE (@0)) + && types_match (@0, @1)) + (ncmp (bit_xor @0 @1) @2)))) + /* If we have (A & C) == C where C is a power of 2, convert this into (A & C) != 0. Similarly for NE_EXPR. */ (for cmp (eq ne) |