diff mbox

[wwwdocs] Re: [2/2] tree-ssa-strlen optimization pass

Message ID 20110929130217.GU2687@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Sept. 29, 2011, 1:02 p.m. UTC
Hi!

On Mon, Sep 26, 2011 at 04:33:05PM +0200, Richard Guenther wrote:
> Btw, can you add a changes.html entry for this?

Like this?



	Jakub

Comments

Richard Biener Sept. 29, 2011, 1:07 p.m. UTC | #1
On Thu, Sep 29, 2011 at 3:02 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> On Mon, Sep 26, 2011 at 04:33:05PM +0200, Richard Guenther wrote:
>> Btw, can you add a changes.html entry for this?
>
> Like this?

Yes.

Thanks,
Richard.

> --- htdocs/gcc-4.7/changes.html 27 Sep 2011 18:42:56 -0000      1.38
> +++ htdocs/gcc-4.7/changes.html 29 Sep 2011 12:56:42 -0000
> @@ -124,6 +124,48 @@ void bar (void)
>       possibly only by inlining all calls.  Cloning causes a lot less code size
>       growth.</li>
>     </ul></li>
> +
> +    <li>String length optimization pass has been added.  This pass attempts
> +      to track string lengths and optimize various standard C string functions
> +      like <code>strlen</code>, <code>strchr</code>, <code>strcpy</code>,
> +      <code>strcat</code>, <code>stpcpy</code> and their
> +      <code>_FORTIFY_SOURCE</code> counterparts into faster alternatives.
> +      This pass is enabled by default at <code>-O2</code> or above, unless
> +      optimizing for size, and can be disabled by
> +      <code>-fno-optimize-strlen</code> option.  The pass can e.g. optimize
> +      <pre>
> +char *bar (const char *a)
> +{
> +  size_t l = strlen (a) + 2;
> +  char *p = malloc (l); if (p == NULL) return p;
> +  strcpy (p, a); strcat (p, "/"); return p;
> +}
> +      </pre>
> +      can be optimized into:
> +      <pre>
> +char *bar (const char *a)
> +{
> +  size_t tmp = strlen (a);
> +  char *p = malloc (tmp + 2); if (p == NULL) return p;
> +  memcpy (p, a, tmp); memcpy (p + tmp, "/", 2); return p;
> +}
> +      </pre>
> +      or for hosted compilations where <code>stpcpy</code> is available in the
> +      runtime and headers provide its prototype, e.g.
> +      <pre>
> +void foo (char *a, const char *b, const char *c, const char *d)
> +{
> +  strcpy (a, b); strcat (a, c); strcat (a, d);
> +}
> +      </pre>
> +      into:
> +      <pre>
> +void foo (char *a, const char *b, const char *c, const char *d)
> +{
> +  strcpy (stpcpy (stpcpy (a, b), c), d);
> +}
> +      </pre>
> +    </li>
>   </ul>
>
>  <h2>New Languages and Language specific improvements</h2>
>
>
>        Jakub
>
diff mbox

Patch

--- htdocs/gcc-4.7/changes.html	27 Sep 2011 18:42:56 -0000	1.38
+++ htdocs/gcc-4.7/changes.html	29 Sep 2011 12:56:42 -0000
@@ -124,6 +124,48 @@  void bar (void)
       possibly only by inlining all calls.  Cloning causes a lot less code size
       growth.</li>
     </ul></li>
+
+    <li>String length optimization pass has been added.  This pass attempts
+      to track string lengths and optimize various standard C string functions
+      like <code>strlen</code>, <code>strchr</code>, <code>strcpy</code>,
+      <code>strcat</code>, <code>stpcpy</code> and their
+      <code>_FORTIFY_SOURCE</code> counterparts into faster alternatives.
+      This pass is enabled by default at <code>-O2</code> or above, unless
+      optimizing for size, and can be disabled by
+      <code>-fno-optimize-strlen</code> option.  The pass can e.g. optimize
+      <pre>
+char *bar (const char *a)
+{
+  size_t l = strlen (a) + 2;
+  char *p = malloc (l); if (p == NULL) return p;
+  strcpy (p, a); strcat (p, "/"); return p;
+}
+      </pre>
+      can be optimized into:
+      <pre>
+char *bar (const char *a)
+{
+  size_t tmp = strlen (a);
+  char *p = malloc (tmp + 2); if (p == NULL) return p;
+  memcpy (p, a, tmp); memcpy (p + tmp, "/", 2); return p;
+}
+      </pre>
+      or for hosted compilations where <code>stpcpy</code> is available in the
+      runtime and headers provide its prototype, e.g.
+      <pre>
+void foo (char *a, const char *b, const char *c, const char *d)
+{
+  strcpy (a, b); strcat (a, c); strcat (a, d);
+}
+      </pre>
+      into:
+      <pre>
+void foo (char *a, const char *b, const char *c, const char *d)
+{
+  strcpy (stpcpy (stpcpy (a, b), c), d);
+}
+      </pre>
+    </li>
   </ul>
 
 <h2>New Languages and Language specific improvements</h2>