aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <quic_apinski@quicinc.com>2024-05-25 23:29:48 -0700
committerAndrew Pinski <quic_apinski@quicinc.com>2024-05-29 08:54:09 -0700
commit0a9154d154957b21eb2c9e4fbe9869e50fb9742f (patch)
tree8c23d30c6374cbb0524a34be322855184b69b309 /gcc
parent39263ed2d39ac1cebde59bc5e72ddcad5dc7a1ec (diff)
downloadgcc-0a9154d154957b21eb2c9e4fbe9869e50fb9742f.zip
gcc-0a9154d154957b21eb2c9e4fbe9869e50fb9742f.tar.gz
gcc-0a9154d154957b21eb2c9e4fbe9869e50fb9742f.tar.bz2
Match: Add maybe_bit_not instead of plain matching
While working on adding matching of negative expressions of `a - b`, I noticed that we started to have "duplicated" patterns due to not having a way to match maybe negative expressions. So I went back to what I did for bit_not and decided to improve the situtation there so for some patterns where we had 2 operands of an expression where one could have been a bit_not, add back maybe_bit_not. This does not add maybe_bit_not in every place were bitwise_inverted_equal_p is used, just the ones were 2 operands of an expression could be swapped. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd (bit_not_with_nop): Unconditionalize. (maybe_cmp): Likewise. (maybe_bit_not): New match pattern. (`~X & X`): Use maybe_bit_not and add `:c` back. (`~x ^ x`/`~x | x`): Likewise. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd14
1 files changed, 10 insertions, 4 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 024e335..090ad4e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -167,7 +167,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0)))
&& tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@0))))))
-#if GIMPLE
/* These are used by gimple_bitwise_inverted_equal_p to simplify
detection of BIT_NOT and comparisons. */
(match (bit_not_with_nop @0)
@@ -188,7 +187,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bit_xor@0 @1 @2)
(if (INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) == 1)))
-#endif
+/* maybe_bit_not is used to match what
+ is acceptable for bitwise_inverted_equal_p. */
+(match (maybe_bit_not @0)
+ (bit_not_with_nop@0 @1))
+(match (maybe_bit_not @0)
+ (INTEGER_CST@0))
+(match (maybe_bit_not @0)
+ (maybe_cmp@0 @1))
/* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR <x>
ABSU_EXPR returns unsigned absolute value of the operand and the operand
@@ -1332,7 +1338,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* Simplify ~X & X as zero. */
(simplify
- (bit_and (convert? @0) (convert? @1))
+ (bit_and:c (convert? @0) (convert? (maybe_bit_not @1)))
(with { bool wascmp; }
(if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
&& bitwise_inverted_equal_p (@0, @1, wascmp))
@@ -1597,7 +1603,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* ~x ^ x -> -1 */
(for op (bit_ior bit_xor)
(simplify
- (op (convert? @0) (convert? @1))
+ (op:c (convert? @0) (convert? (maybe_bit_not @1)))
(with { bool wascmp; }
(if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
&& bitwise_inverted_equal_p (@0, @1, wascmp))