This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR70701
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 18 Apr 2016 12:42:46 +0200 (CEST)
- Subject: [PATCH] Fix PR70701
- Authentication-results: sourceware.org; auth=none
The following fixes a missed optimization when value-numbering
translates through memcpy calls.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
Richard.
2016-04-18 Richard Biener <rguenther@suse.de>
PR tree-optimization/70701
* tree-ssa-sccvn.c (vn_reference_lookup_3): Resolve fully constant
references after translating through a memcpy.
* gcc.dg/tree-ssa/ssa-fre-53.c: New testcase.
Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c (revision 235017)
--- gcc/tree-ssa-sccvn.c (working copy)
*************** vn_reference_lookup_3 (ao_ref *ref, tree
*** 2152,2157 ****
--- 2340,2351 ----
vr->operands[1] = op;
vr->hashcode = vn_reference_compute_hash (vr);
+ /* Try folding the new reference to a constant. */
+ tree val = fully_constant_vn_reference_p (vr);
+ if (val)
+ return vn_reference_lookup_or_insert_for_pieces
+ (vuse, vr->set, vr->type, vr->operands, val);
+
/* Adjust *ref from the new operands. */
if (!ao_ref_init_from_vn_reference (&r, vr->set, vr->type, vr->operands))
return (void *)-1;
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-53.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-53.c (revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-53.c (working copy)
***************
*** 0 ****
--- 1,11 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fno-tree-forwprop -fdump-tree-fre1" } */
+
+ const int a[]={1,2,3};
+ int f(){
+ int*b=__builtin_malloc(12);
+ __builtin_memcpy(b,a,12);
+ return b[0];
+ }
+
+ /* { dg-final { scan-tree-dump "return 1;" "fre1" } } */