]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-ssa-dom.c (find_equivalent_equality_comparison): Do not a eliminate type convers...
authorJeff Law <law@redhat.com>
Sat, 2 Jul 2005 14:15:11 +0000 (08:15 -0600)
committerJeff Law <law@gcc.gnu.org>
Sat, 2 Jul 2005 14:15:11 +0000 (08:15 -0600)
        * tree-ssa-dom.c (find_equivalent_equality_comparison): Do not
        a eliminate type conversion which feeds an equality comparison
        if the original type or either operand in the comparison is a
        function pointer.

* gcc.dg/tree-ssa/pr22051-1.c: New test.
* gcc.dg/tree-ssa/pr22051-2.c: New test.

From-SVN: r101534

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr22051-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr22051-2.c [new file with mode: 0644]
gcc/tree-ssa-dom.c

index ca0762e7d45e5b61b755909d46ed6b58febf3412..6e5396a04a261edc0b83fc5470261e24201d0e6e 100644 (file)
@@ -1,3 +1,10 @@
+2005-07-02  Jeff Law  <law@redhat.com>
+
+       * tree-ssa-dom.c (find_equivalent_equality_comparison): Do not
+       a eliminate type conversion which feeds an equality comparison
+       if the original type or either operand in the comparison is a
+       function pointer.
+
 2005-07-02  Joseph S. Myers  <joseph@codesourcery.com>
 
        * c.opt, common.opt, config/bfin/bfin.opt, config/pa/pa.opt,
index 65caac9e4e16e09bdaaa43ee3310862c504fbae2..320f6ecf10a182ac1adb2cdb2126f06f189346f0 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-02  Jeff Law  <law@redhat.com>
+
+       * gcc.dg/tree-ssa/pr22051-1.c: New test.
+       * gcc.dg/tree-ssa/pr22051-2.c: New test.
+
 2005-07-02  Joseph S. Myers  <joseph@codesourcery.com>
 
        * gcc.dg/format/gcc_diag-1.c: Update.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr22051-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr22051-1.c
new file mode 100644 (file)
index 0000000..4815be0
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile }  */
+/* { dg-options "-O2 -fdump-tree-optimized" }  */
+
+
+void *arf ();
+int
+foo()
+{
+  void *p = arf ();
+
+  if ((void (*)(void))p != 0)
+    return 1;
+  else
+    return 2;
+}
+
+/* The cast to a function pointer type must remain after all optimizations
+   are complete so that function pointer canonicalization works on those
+   targets which require it.  */
+/* { dg-final { scan-tree-dump-times "if \\(\\(void \\(\\*<.*>\\) \\(void\\)\\) p" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr22051-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr22051-2.c
new file mode 100644 (file)
index 0000000..aa4c00a
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile }  */
+/* { dg-options "-O2 -fdump-tree-optimized -w" }  */
+
+
+
+
+void *arf ();
+int
+foo()
+{
+  void (*q)(void);
+  int r = q;
+
+  if (r != 0)
+    return 1;
+  else
+    return 2;
+}
+
+/* The cast to an int type must remain after all optimizations are complete
+   so that we do not try to canonicalize a function pointer for the
+   comparison when no such canonicalization is wanted.  */
+/* { dg-final { scan-tree-dump-times "if \\(\\(int\\) q" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+
index 86da07b437f3c8578a1669a98c9ae1b105cfc79e..e341a68242aea7f4dba53147a22cdee450dd56a5 100644 (file)
@@ -1882,6 +1882,18 @@ find_equivalent_equality_comparison (tree cond)
     {
       tree def_rhs = TREE_OPERAND (def_stmt, 1);
 
+
+      /* If either operand to the comparison is a pointer to
+        a function, then we can not apply this optimization
+        as some targets require function pointers to be
+        canonicalized and in this case this optimization would
+        eliminate a necessary canonicalization.  */
+      if ((POINTER_TYPE_P (TREE_TYPE (op0))
+          && TREE_CODE (TREE_TYPE (TREE_TYPE (op0))) == FUNCTION_TYPE)
+         || (POINTER_TYPE_P (TREE_TYPE (op1))
+             && TREE_CODE (TREE_TYPE (TREE_TYPE (op1))) == FUNCTION_TYPE))
+       return NULL;
+             
       /* Now make sure the RHS of the MODIFY_EXPR is a typecast.  */
       if ((TREE_CODE (def_rhs) == NOP_EXPR
           || TREE_CODE (def_rhs) == CONVERT_EXPR)
@@ -1895,6 +1907,16 @@ find_equivalent_equality_comparison (tree cond)
              > TYPE_PRECISION (TREE_TYPE (def_rhs)))
            return NULL;
 
+         /* If the inner type of the conversion is a pointer to
+            a function, then we can not apply this optimization
+            as some targets require function pointers to be
+            canonicalized.  This optimization would result in
+            canonicalization of the pointer when it was not originally
+            needed/intended.  */
+         if (POINTER_TYPE_P (def_rhs_inner_type)
+             && TREE_CODE (TREE_TYPE (def_rhs_inner_type)) == FUNCTION_TYPE)
+           return NULL;
+
          /* What we want to prove is that if we convert OP1 to
             the type of the object inside the NOP_EXPR that the
             result is still equivalent to SRC.