[PATCH] Fix PR43213
Richard Guenther
rguenther@suse.de
Mon Mar 1 12:55:00 GMT 2010
This fixes PR43213 - we probably miss this optimization because of
the expand from SSA changes. The easiest fix is to just ask the
alias-oracle if the result-decl is aliased by the rhs.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2010-03-01 Richard Guenther <rguenther@suse.de>
PR middle-end/43213
* expr.c (expand_assignment): Use the alias-oracle to tell
if the rhs aliases the result decl.
* gcc.dg/pr43213.c: New testcase.
Index: gcc/testsuite/gcc.dg/pr43213.c
===================================================================
*** gcc/testsuite/gcc.dg/pr43213.c (revision 0)
--- gcc/testsuite/gcc.dg/pr43213.c (revision 0)
***************
*** 0 ****
--- 1,12 ----
+ /* { dg-do compile } */
+
+ struct S {
+ int i;
+ };
+
+ struct S f(int i)
+ {
+ return *(struct S *)&i;
+ }
+
+ /* { dg-final { scan-assembler-not "memmove" } } */
Index: gcc/expr.c
===================================================================
*** gcc/expr.c (revision 157134)
--- gcc/expr.c (working copy)
*************** expand_assignment (tree to, tree from, b
*** 4432,4440 ****
/* In case we are returning the contents of an object which overlaps
the place the value is being stored, use a safe function when copying
a value through a pointer into a structure value return block. */
! if (TREE_CODE (to) == RESULT_DECL && TREE_CODE (from) == INDIRECT_REF
&& ADDR_SPACE_GENERIC_P
! (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
&& cfun->returns_struct
&& !cfun->returns_pcc_struct)
{
--- 4432,4442 ----
/* In case we are returning the contents of an object which overlaps
the place the value is being stored, use a safe function when copying
a value through a pointer into a structure value return block. */
! if (TREE_CODE (to) == RESULT_DECL
! && TREE_CODE (from) == INDIRECT_REF
&& ADDR_SPACE_GENERIC_P
! (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
! && refs_may_alias_p (to, from)
&& cfun->returns_struct
&& !cfun->returns_pcc_struct)
{
More information about the Gcc-patches
mailing list