re PR middle-end/87188 (Function pointer canonicalization optimized away)
authorJohn David Anglin <danglin@gcc.gnu.org>
Fri, 14 Sep 2018 23:26:12 +0000 (23:26 +0000)
committerJohn David Anglin <danglin@gcc.gnu.org>
Fri, 14 Sep 2018 23:26:12 +0000 (23:26 +0000)
PR middle-end/87188
* dojump.c (do_compare_and_jump): Canonicalize function pointers
when one operand is a function pointer.  Use POINTER_TYPE_P and
FUNC_OR_METHOD_TYPE_P.
* expr.c (do_store_flag): Use POINTER_TYPE_P and FUNC_OR_METHOD_TYPE_P.
* fold-const.c (build_range_check): Likewise.
* match.pd (simple_comparison): Likewise.

From-SVN: r264336

gcc/ChangeLog
gcc/dojump.c
gcc/expr.c
gcc/fold-const.c
gcc/match.pd

index a2088aa9587380ad76842ced0586e8550f6bf706..8fda90ac6ce684701e00d3195e8c4459ec6a94d4 100644 (file)
@@ -1,3 +1,13 @@
+2018-09-14  John David Anglin  <danglin@gcc.gnu.org>
+
+       PR middle-end/87188
+       * dojump.c (do_compare_and_jump): Canonicalize function pointers
+       when one operand is a function pointer.  Use POINTER_TYPE_P and
+       FUNC_OR_METHOD_TYPE_P.
+       * expr.c (do_store_flag): Use POINTER_TYPE_P and FUNC_OR_METHOD_TYPE_P.
+       * fold-const.c (build_range_check): Likewise.
+       * match.pd (simple_comparison): Likewise.
+
 2018-09-14  David Malcolm  <dmalcolm@redhat.com>
 
        PR c/82967
index 88cc96ae85ae2e799c1af8969b9d7835fb74d907..56c82c5fdb5b60e674aa355d4e78832ae229a099 100644 (file)
@@ -1215,15 +1215,15 @@ do_compare_and_jump (tree treeop0, tree treeop1, enum rtx_code signed_code,
   code = unsignedp ? unsigned_code : signed_code;
 
   /* If function pointers need to be "canonicalized" before they can
-     be reliably compared, then canonicalize them.
-     Only do this if *both* sides of the comparison are function pointers.
-     If one side isn't, we want a noncanonicalized comparison.  See PR
-     middle-end/17564.  */
+     be reliably compared, then canonicalize them.  Canonicalize the
+     expression when one of the operands is a function pointer.  This
+     handles the case where the other operand is a void pointer.  See
+     PR middle-end/17564.  */
   if (targetm.have_canonicalize_funcptr_for_compare ()
-      && POINTER_TYPE_P (TREE_TYPE (treeop0))
-      && POINTER_TYPE_P (TREE_TYPE (treeop1))
-      && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))
-      && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (treeop1))))
+      && ((POINTER_TYPE_P (TREE_TYPE (treeop0))
+          && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0))))
+         || (POINTER_TYPE_P (TREE_TYPE (treeop1))
+             && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (treeop1))))))
     {
       rtx new_op0 = gen_reg_rtx (mode);
       rtx new_op1 = gen_reg_rtx (mode);
index 67aa0520e4432a5d05a14a820b1e7b91ace03157..b8782b9b1339e49b974a1fe22394293ba089fca7 100644 (file)
@@ -11842,12 +11842,10 @@ do_store_flag (sepops ops, rtx target, machine_mode mode)
   /* We won't bother with store-flag operations involving function pointers
      when function pointers must be canonicalized before comparisons.  */
   if (targetm.have_canonicalize_funcptr_for_compare ()
-      && ((TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE
-          && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0)))
-              == FUNCTION_TYPE))
-         || (TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE
-             && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1)))
-                 == FUNCTION_TYPE))))
+      && ((POINTER_TYPE_P (TREE_TYPE (arg0))
+          && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg0))))
+         || (POINTER_TYPE_P (TREE_TYPE (arg1))
+             && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg1))))))
     return 0;
 
   STRIP_NOPS (arg0);
index 6b4b6a423ca41e8901bb03a8945a88130aa38345..3a6d1b19b487c830e52a3913d448bc369998c0e0 100644 (file)
@@ -4956,8 +4956,8 @@ build_range_check (location_t loc, tree type, tree exp, int in_p,
   /* Disable this optimization for function pointer expressions
      on targets that require function pointer canonicalization.  */
   if (targetm.have_canonicalize_funcptr_for_compare ()
-      && TREE_CODE (etype) == POINTER_TYPE
-      && TREE_CODE (TREE_TYPE (etype)) == FUNCTION_TYPE)
+      && POINTER_TYPE_P (etype)
+      && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (etype)))
     return NULL_TREE;
 
   if (! in_p)
index 6d54dcb6f69d22aea8ba5135a9df24e9074c890b..74244f348a03951cbb4683a00a844d696f90ffad 100644 (file)
@@ -3558,8 +3558,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        /* Disable this optimization if we're casting a function pointer
          type on targets that require function pointer canonicalization.  */
        && !(targetm.have_canonicalize_funcptr_for_compare ()
-           && TREE_CODE (TREE_TYPE (@00)) == POINTER_TYPE
-           && TREE_CODE (TREE_TYPE (TREE_TYPE (@00))) == FUNCTION_TYPE)
+           && POINTER_TYPE_P (TREE_TYPE (@00))
+           && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@00))))
        && single_use (@0))
    (if (TYPE_PRECISION (TREE_TYPE (@00)) == TYPE_PRECISION (TREE_TYPE (@0))
        && (TREE_CODE (@10) == INTEGER_CST