builtins.c (expand_builtin_strlen): Evaluate the lengths of string literals at compil...
authorRoger Sayle <roger@eyesopen.com>
Mon, 14 Apr 2003 20:23:27 +0000 (20:23 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Mon, 14 Apr 2003 20:23:27 +0000 (20:23 +0000)
* builtins.c (expand_builtin_strlen):  Evaluate the lengths of
string literals at compile-time.

From-SVN: r65585

gcc/ChangeLog
gcc/builtins.c

index bf118416c75789a85d1e32432477f0688fee0007..72d5d0a6e46505a0b630bc75143e3cf809ecf724 100644 (file)
@@ -1,3 +1,8 @@
+2003-04-14  Roger Sayle  <roger@eyesopen.com>
+
+       * builtins.c (expand_builtin_strlen):  Evaluate the lengths of
+       string literals at compile-time.
+
 2003-04-14  Roger Sayle  <roger@eyesopen.com>
 
        * fold-const.c (fold):  Transform (c1 - x) cmp c2, where cmp is a
index 1519593b883a4eb546599271cceabff30d425ece..89f9531c8d3c41e65a9ab4379161d9a3a8583fe0 100644 (file)
@@ -1935,14 +1935,18 @@ expand_builtin_strlen (exp, target)
   else
     {
       rtx pat;
-      tree src = TREE_VALUE (arglist);
-
-      int align
-       = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
-
+      tree len, src = TREE_VALUE (arglist);
       rtx result, src_reg, char_rtx, before_strlen;
       enum machine_mode insn_mode = value_mode, char_mode;
       enum insn_code icode = CODE_FOR_nothing;
+      int align;
+
+      /* If the length can be computed at compile-time, return it.  */
+      len = c_strlen (src);
+      if (len)
+       return expand_expr (len, target, value_mode, EXPAND_NORMAL);
+
+      align = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
 
       /* If SRC is not a pointer type, don't do this operation inline.  */
       if (align == 0)