[PATCH] Don't invalidate string length cache when not needed
Jakub Jelinek
jakub@redhat.com
Thu May 16 14:28:00 GMT 2013
On Thu, May 16, 2013 at 04:18:27PM +0200, Jakub Jelinek wrote:
> As q could point to p, if we didn't do what your patch does on the p[0] = 'X';
> store, then we'd need to invalidate the recorded length of the q string.
> Similarly if there is p[0] = '\0' or p[0] = var.
Ah, another thing while we are at it.
For p[0] = '\0'; case when p[0] is known to be '\0' already, we
remove it if:
/* When storing '\0', the store can be removed
if we know it has been stored in the current function. */
if (!stmt_could_throw_p (stmt) && si->writable)
(and in that case don't invalidate anything either). But the above
condition is false, we set si->writable (correct) and si->dont_invalidate,
while we could do instead of that the same what you do for non-zero store to
non-zero location, i.e. gsi_next (gsi); return false;.
Perhaps a testcase for that is:
size_t
bar (char *p, char *r)
{
size_t len1 = strlen (r);
char *q = strchr (p, '\0');
*q = '\0';
return len1 - strlen (r); // This strlen should be optimized into len1.
}
strlen (q) should be known to be zero at that point, but si->writable should
be false, we don't know if p doesn't point say into .rodata, and
stmt_could_throw_p probably should return true too.
Jakub
More information about the Gcc-patches
mailing list