This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH, Pointer Bounds Checker 14/x] Passes [12/n] Optimize string functions
- From: Jeff Law <law at redhat dot com>
- To: Ilya Enkovich <enkovich dot gnu at gmail dot com>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 09 Oct 2014 11:02:02 -0600
- Subject: Re: [PATCH, Pointer Bounds Checker 14/x] Passes [12/n] Optimize string functions
- Authentication-results: sourceware.org; auth=none
- References: <20141008191815 dot GL13454 at msticlxl57 dot ims dot intel dot com>
On 10/08/14 13:18, Ilya Enkovich wrote:
This patch introduces simple optimization of string function calls using variants with no checks and/or bounds copy when possible.
2014-10-08 Ilya Enkovich <email@example.com>
* tree-chkp.c (check_infos): New.
Just a note, these reviews are going to come out-of-order.
I thought I mentioned it in the prior message. Can you pull the
optimization stuff into its own file. It seems to me it ought to be
conceptually separate from expansion and the other miscellaneous stuff
So is the purpose here to expose the checks that would normally be done
in the mem* routines to their caller in the hopes that doing so will
expose redundant checks? Or is there some other reason?
+/* Find memcpy, mempcpy, memmove and memset calls, perform
+ checks before call and then call no_chk version of
+ functions. We do it on O2 to enable inlining of these
+ functions during expand.
Can you please include tests for both classes of transformations? It
doesn't have to be exhaustive, just a few simple tests to both verify
the transformation is working today and to help ensure nobody breaks it
in the future?
+ Also try to find memcpy, mempcpy, memmove and memset calls
+ which are known to not write pointers to memory and use
+ faster function versions for them. */
+ basic_block bb;
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "Searching for replacable string function calls...\n");
Seems like if you're going to emit a message into the debug file that
the compiler is searching for replaceable calls that you ought to emit a
message when a replaceable call is found too.
And doing so ought to make writing those testcases easier too since you
can scan the appropriate dump file for the message :-)
+ if (fndecl_nochk)
+ fndecl = fndecl_nochk;
+ gimple_call_set_fndecl (stmt, fndecl);
+ /* If there is no nochk version of function then
+ do nothing. Otherwise insert checks before
+ the call. */
+ if (!fndecl_nochk)
It's a nit, but I'd tend to write that as:
fndecl = fndecl_nochk
gimple_call_set_fndecl (stmt, fndecl);
+ to perform runtiome check for size and perform
Basically we have a point (denoted by an iterator) and we want to split
the block at that point and insert a conditional around some new blob of
code before the original split point.
+ checks only when size is not zero. */
+ if (!known)
+ gimple check = gimple_build_cond (NE_EXPR,
+ /* Split block before string function call. */
+ j = i;
+ gsi_prev (&j);
+ fall = split_block (bb, gsi_stmt (j));
+ bb = fall->src;
+ /* Add size check. */
+ j = gsi_last_bb (bb);
+ if (gsi_end_p (j))
+ gsi_insert_before (&j, check, GSI_SAME_STMT);
+ gsi_insert_after (&j, check, GSI_SAME_STMT);
+ /* Create basic block for checks. */
+ check_bb = create_empty_bb (bb);
+ make_edge (bb, check_bb, EDGE_TRUE_VALUE);
+ make_single_succ_edge (check_bb, fall->dest, EDGE_FALLTHRU);
+ /* Fix edge for splitted bb. */
+ fall->flags = EDGE_FALSE_VALUE;
+ fall->count = bb->count;
+ fall->probability = REG_BR_PROB_BASE;
+ /* Update dominance info. */
+ if (dom_info_available_p (CDI_DOMINATORS))
+ set_immediate_dominator (CDI_DOMINATORS, check_bb, bb);
+ set_immediate_dominator (CDI_DOMINATORS, fall->dest, bb);
+ /* Update loop info. */
+ if (current_loops)
+ add_bb_to_loop (check_bb, bb->loop_father);
+ /* Set position for checks. */
+ j = gsi_last_bb (check_bb);
+ /* The block was splitted and therefore we
+ need to set iterator to its end. */
+ i = gsi_last_bb (bb);
I'm a bit surprised we don't have this kind of capability already broken
out. But assuming that's the case, can you go ahead and break that out
into its own little helper function? You don't need to find all the
cases where we're doing this kind of thing today, just create the helper
function and use it in your new code.
You incrementally update the dominance information, so is there really a
need to free it here? ie, the data is still valid, so I think we can
just avoid the free_dominance_info calls.
+/* Finalise checker optimization pass. */
+ chkp_fix_cfg ();
+ free_dominance_info (CDI_DOMINATORS);
+ free_dominance_info (CDI_POST_DOMINATORS);
Passes after this which use dominator information then won't have to
rebuild it from scratch.
Generally this looks good. With the light changes above, this will be OK.