diff options
author | Richard Biener <rguenther@suse.de> | 2023-06-16 11:47:45 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-06-16 13:46:22 +0200 |
commit | 69b04fe7445c88edafd6983e28353a158e4314b5 (patch) | |
tree | d763afc20a88257f22bafe50bea7f5e7098ac925 | |
parent | 453cb585f0f8673a5d69d1b420ffd4b3f53aca00 (diff) | |
download | gcc-69b04fe7445c88edafd6983e28353a158e4314b5.zip gcc-69b04fe7445c88edafd6983e28353a158e4314b5.tar.gz gcc-69b04fe7445c88edafd6983e28353a158e4314b5.tar.bz2 |
tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false
The following adds two patterns simplifying comparisons,
uns < (typeof uns)(uns != 0) is always false and x != (typeof x)(x == 0)
is always true.
PR tree-optimization/110278
* match.pd (uns < (typeof uns)(uns != 0) -> false): New.
(x != (typeof x)(x == 0) -> true): Likewise.
-rw-r--r-- | gcc/match.pd | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index b7baad6..2dd2382 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6410,6 +6410,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cmp == GT_EXPR) (lt (view_convert:st @0) { build_zero_cst (st); }))))))))))) +/* unsigned < (typeof unsigned)(unsigned != 0) is always false. */ +(simplify + (lt:c @0 (convert (ne @0 integer_zerop))) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + { constant_boolean_node (false, type); })) + +/* x != (typeof x)(x == 0) is always true. */ +(simplify + (ne:c @0 (convert (eq @0 integer_zerop))) + { constant_boolean_node (true, type); }) + (for cmp (unordered ordered unlt unle ungt unge uneq ltgt) /* If the second operand is NaN, the result is constant. */ (simplify |