On 4 August 2016 at 12:39, Richard Biener <rguent...@suse.de> wrote:
> On Thu, 4 Aug 2016, Prathamesh Kulkarni wrote:
>
>> Hi,
>> The attached patch fixes pr22051-2.c which regressed due to
>> r238754. Matthew, could you please confirm if this patch fixes the
>> test-case for you ?
>>
>> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>> Cross tested on arm*-*-*.
>> OK for trunk ?
>
> Note that if function pointer types are really the issue then
> you also need to handle METHOD_TYPE, thus sth like
>
>   && ! FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@0))
>
> please also add a comment for this non-obvious thing.  I believe
> we should simply apply function pointer canonicalization for
> comparisons early during gimplification - exposing this target
> detail only during RTL expansion makes generic optimization hard.
>
> Ok with those changes.
Is the attached version OK ?
Bootstrapped on x86_64-unknown-linux-gnu, cross-tested on arm*-*-*.

Thanks,
Prathamesh
>
> Thanks,
> Richard.
2016-08-05  Prathamesh Kulkarni  <prathamesh.kulka...@linaro.org>

        * match.pd ((intptr_t) x eq/ne CST to x eq/ne (typeof x) cst): Disable
        transform if operand's type is pointer to function or method.

diff --git a/gcc/match.pd b/gcc/match.pd
index 2380d90..ac7cfff 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2528,12 +2528,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    { 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 */
+   and (typeof ptr_cst) x eq/ne ptr_cst to x eq/ne (typeof x) CST.
+   Disable the transform if either operand is pointer to function.
+   This broke pr22051-2.c for arm where function pointer
+   canonicalizaion is not wanted.  */
+ 
 (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))))
+  (if ((POINTER_TYPE_P (TREE_TYPE (@0)) && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE 
(TREE_TYPE (@0)))
+       && INTEGRAL_TYPE_P (TREE_TYPE (@1)))
+      || (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && POINTER_TYPE_P (TREE_TYPE (@1))
+         && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@1)))))
    (cmp @0 (convert @1)))))
 
 /* Non-equality compare simplifications from fold_binary  */

Reply via email to