Hello,this lets ldist ignore clobbers. In the testcase, this makes us lose the information that b is clobbered, but being able to distribute seems worth it.
Bootstrap+regtest on x86_64-pc-linux-gnu. 2019-05-03 Marc Glisse <marc.gli...@inria.fr> PR tree-optimization/90269 gcc/ * tree-loop-distribution.c (find_seed_stmts_for_distribution): Ignore clobbers. gcc/testsuite/ * g++.dg/tree-ssa/ldist-1.C: New file. -- Marc Glisse
Index: gcc/testsuite/g++.dg/tree-ssa/ldist-1.C =================================================================== --- gcc/testsuite/g++.dg/tree-ssa/ldist-1.C (nonexistent) +++ gcc/testsuite/g++.dg/tree-ssa/ldist-1.C (working copy) @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-ldist-details" } */ + +#include <new> +struct T { + int* p; + T(T const&t):p(t.p){} +}; +void f(T*__restrict a,T*__restrict b){ + for(int i=0;i<1024;++i){ + new(a+i)T(b[i]); + b[i].~T(); + } +} + +/* { dg-final { scan-tree-dump "generated memcpy" "ldist" } } */ Index: gcc/tree-loop-distribution.c =================================================================== --- gcc/tree-loop-distribution.c (revision 270818) +++ gcc/tree-loop-distribution.c (working copy) @@ -3033,20 +3033,24 @@ find_seed_stmts_for_distribution (struct the loop. */ if (!stmt_has_scalar_dependences_outside_loop (loop, phi)) continue; work_list->safe_push (phi); } for (gimple_stmt_iterator gsi = gsi_start_bb (bbs[i]); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); + /* Ignore clobbers, they do not have true side effects. */ + if (gimple_clobber_p (stmt)) + continue; + /* If there is a stmt with side-effects bail out - we cannot and should not distribute this loop. */ if (gimple_has_side_effects (stmt)) { free (bbs); return false; } /* Distribute stmts which have defs that are used outside of the loop. */