This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: calloc = malloc + memset


Let me ping this. There's no hurry, but it may have got lost with 4.9 approaching.
http://gcc.gnu.org/ml/gcc-patches/2014-03/msg01205.html


On Sun, 23 Mar 2014, Marc Glisse wrote:

On Mon, 3 Mar 2014, Richard Biener wrote:

That's a bit much of ad-hoc pattern-matching ... wouldn't be
p = malloc (n);
memset (p, 0, n);

transform better suited to the strlen opt pass?  After all that tracks
what 'string' is associated with a SSA name pointer through
arbitrary satements using a lattice.

Like this? I had to move the strlen pass after the loop passes (and
after dom or everything was too dirty) but long enough before the end
(some optimizations are necessary after strlen). As a bonus, one more
strlen is optimized in the current testcases :-)

Running the pass twice would be another option I guess (it would require
implementing the clone method), but without a testcase showing it is
needed...

Passes bootstrap+testsuite on x86_64-linux-gnu.

2014-03-23  Marc Glisse  <marc.glisse@inria.fr>

       PR tree-optimization/57742
gcc/
       * tree-ssa-strlen.c (get_string_length): Ignore malloc.
       (handle_builtin_malloc, handle_builtin_memset): New functions.
	(strlen_optimize_stmt): Call them.
	* passes.def: Move strlen after loop+dom.
gcc/testsuite/
       * g++.dg/tree-ssa/calloc.C: New testcase.
       * gcc.dg/tree-ssa/calloc-1.c: Likewise.
       * gcc.dg/tree-ssa/calloc-2.c: Likewise.
	* gcc.dg/strlenopt-9.c: Adapt.

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]