@@ -2611,6 +2611,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
{ constant_boolean_node (cmp == ORDERED_EXPR || cmp == LTGT_EXPR
? false : true, type); })))
+/* PR57371: Transform (double)i eq/ne 0 to i eq/ne 0. */
+(for cmp (ne eq)
+ (simplify
+ (cmp (float @0) real_zerop@1)
+ (if (!flag_trapping_math && INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+ (cmp @0 { build_zero_cst (TREE_TYPE (@0)); }))))
+
/* bool_var != 0 becomes bool_var. */
(simplify
(ne @0 integer_zerop)
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-trapping-math -fdump-tree-gimple" } */
+
+int f1(int i)
+{
+ return (double)i != 0;
+}
+
+int f2(int i)
+{
+ return (double)i == 0;
+}
+
+/* { dg-final { scan-tree-dump-times "double" 0 "gimple" } } */
new file mode 100644
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-trapping-math -fdump-tree-forwprop-details" } */
+
+int f1(int i)
+{
+ double x = (double) i;
+ return x != 0.0;
+}
+
+int f2(int i)
+{
+ double x = (double) i;
+ return x == 0.0;
+}
+
+/* { dg-final { scan-tree-dump "i_\[0-9\]*\\(D\\) != 0" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "i_\[0-9\]*\\(D\\) == 0" "forwprop1" } } */