diff --git a/gcc/match.pd b/gcc/match.pd index 21bf617..6c2ec82 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2513,6 +2513,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && ptrs_compare_unequal (@0, @1)) { neeq == EQ_EXPR ? boolean_false_node : boolean_true_node; }))) +/* PR70920: Transform (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST. + and (typeof ptr_cst) x eq/ne ptr_cst to x eq/ne (typeof x) CST */ +(for cmp (ne eq) + (simplify + (cmp (convert @0) INTEGER_CST@1) + (if ((POINTER_TYPE_P (TREE_TYPE (@0)) && INTEGRAL_TYPE_P (TREE_TYPE (@1))) + || (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && POINTER_TYPE_P (TREE_TYPE (@1)))) + (cmp @0 (convert @1))))) + /* Non-equality compare simplifications from fold_binary */ (for cmp (lt gt le ge) /* Comparisons with the highest or lowest possible integer of diff --git a/gcc/testsuite/gcc.dg/pr70920-1.c b/gcc/testsuite/gcc.dg/pr70920-1.c new file mode 100644 index 0000000..9b7e2d0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple" } */ + +#include + +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" } } */ diff --git a/gcc/testsuite/gcc.dg/pr70920-2.c b/gcc/testsuite/gcc.dg/pr70920-2.c new file mode 100644 index 0000000..2db9897 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-2.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop-details" } */ + +#include + +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" } } */ diff --git a/gcc/testsuite/gcc.dg/pr70920-3.c b/gcc/testsuite/gcc.dg/pr70920-3.c new file mode 100644 index 0000000..8b24cbc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-3.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple -Wno-int-to-pointer-cast" } */ + +#include + +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" } } */ diff --git a/gcc/testsuite/gcc.dg/pr70920-4.c b/gcc/testsuite/gcc.dg/pr70920-4.c new file mode 100644 index 0000000..dedb895 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-4.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ccp-details -Wno-int-to-pointer-cast" } */ + +#include + +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 \\(_\[0-9\]* == 0\\)" "ccp1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c index 18f9041..d38e3a8 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c @@ -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