]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false
authorRichard Biener <rguenther@suse.de>
Fri, 16 Jun 2023 09:47:45 +0000 (11:47 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 16 Jun 2023 11:46:22 +0000 (13:46 +0200)
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.

gcc/match.pd

index b7baad6bf1bd028c63d6c21b5544dfc39382c31f..2dd23826034627ac5ee74821d9ec81f92c2a3baa 100644 (file)
@@ -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