@@ -3408,3 +3408,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
{ CONSTRUCTOR_ELT (ctor, idx / k)->value; })
(BIT_FIELD_REF { CONSTRUCTOR_ELT (ctor, idx / k)->value; }
@1 { bitsize_int ((idx % k) * width); })))))))))
+
+/* PR70920: Transform (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST. */
+
+(for cmp (ne eq)
+ (simplify
+ (cmp (convert@2 @0) INTEGER_CST@1)
+ (if (POINTER_TYPE_P (TREE_TYPE (@0))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@2)))
+ (cmp @0 (convert @1)))))
+
+/* Reverse of the above case:
+ x has integral_type, CST is a pointer constant.
+ Transform (typeof CST)x eq/ne CST to x eq/ne (typeof x) CST. */
+
+(for cmp (ne eq)
+ (simplify
+ (cmp (convert @0) @1)
+ (if (POINTER_TYPE_P (TREE_TYPE (@1))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+ (cmp @0 (convert @1)))))
new file mode 100644
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+#include <stdint.h>
+
+void f1();
+void f2();
+
+void
+foo (int *a)
+{
+ if ((intptr_t) a == 0)
+ {
+ f1 ();
+ if (a)
+ f2 ();
+ }
+}
+
+/* { dg-final { scan-tree-dump "if \\(a == 0B\\)" "gimple" } } */
new file mode 100644
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop-details" } */
+
+#include <stdint.h>
+
+void f1();
+void f2();
+
+void
+foo (int *a)
+{
+ int cst = 0;
+ if ((intptr_t) a == cst)
+ {
+ f1 ();
+ if (a)
+ f2 ();
+ }
+}
+
+/* { dg-final { scan-tree-dump "gimple_simplified to if \\(a_\[0-9\]*\\(D\\) == 0B\\)" "forwprop1" } } */
new file mode 100644
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-int-to-pointer-cast -fdump-tree-gimple" } */
+
+#include <stdint.h>
+
+void f1();
+void f2();
+
+void
+foo (int a)
+{
+ if ((int *) a == 0)
+ {
+ f1 ();
+ if (a)
+ f2 ();
+ }
+}
+
+/* { dg-final { scan-tree-dump "if \\(a == 0\\)" "gimple" } } */
new file mode 100644
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop-details -Wno-int-to-pointer-cast" } */
+
+#include <stdint.h>
+
+void f1();
+void f2();
+
+void
+foo (int a)
+{
+ void *cst = 0;
+ if ((int *) a == cst)
+ {
+ f1 ();
+ if (a)
+ f2 ();
+ }
+}
+
+/* { dg-final { scan-tree-dump "gimple_simplified to if \\(a_\[0-9\]*\\(D\\) == 0\\)" "forwprop1" } } */
@@ -21,7 +21,7 @@ try_combine (rtx i1, rtx newpat)
/* There should be three tests against i1. Two from the hash table
dumps, one in the code itself. */
-/* { dg-final { scan-tree-dump-times "if .i1_" 3 "dom2"} } */
+/* { dg-final { scan-tree-dump-times "if .i1_" 2 "dom2"} } */
/* There should be no actual jump threads realized by DOM. The
legitimize jump threads are handled in VRP and those discovered