http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46076
--- Comment #15 from Martin Jambor <jamborm at gcc dot gnu.org> 2011-01-04
17:39:45 UTC ---
I'd also prefer a general solution and would not actually mind very
much if we regressed in cases like this. Nevertheless, if we have a
consensus that we should avoid regressing in 4.6, an ipa-prop.c
specific handling of this situation would probably look very much like
the patch below. Given the discussion above I am not 100% sure it is
always safe but it passes bootstrap and testing (though I do not know
how much it exercises the code path). I'll be happy to submit the
patch with a testcase and a change log and stuff if any maintainer
thinks it is a good idea.
Index: gcc/ipa-prop.c
===================================================================
--- gcc/ipa-prop.c (revision 168424)
+++ gcc/ipa-prop.c (working copy)
@@ -396,6 +396,25 @@ compute_complex_assign_jump_func (struct
}
return;
}
+ else if (!op2 && is_gimple_ip_invariant (op1))
+ {
+ tree name_type = TREE_TYPE (name);
+ tree op_type = TREE_TYPE (op1);
+
+ if (useless_type_conversion_p (name_type, op_type)
+ || (POINTER_TYPE_P (name_type)
+ && POINTER_TYPE_P (op_type)
+ && TREE_CODE (TREE_TYPE (name_type)) == FUNCTION_TYPE
+ && TREE_CODE (TREE_TYPE (op_type)) == FUNCTION_TYPE
+ && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (name_type)))
+ == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (op_type))))
+ && TYPE_ARG_TYPES (TREE_TYPE (name_type)) == void_list_node
+ && !TYPE_ARG_TYPES (TREE_TYPE (op_type))))
+ {
+ jfunc->type = IPA_JF_CONST;
+ jfunc->value.constant = op1;
+ }
+ }
if (TREE_CODE (op1) != ADDR_EXPR)
return;