2 /* { dg-options "-O2 -fno-code-hoisting -fdump-tree-strlen -fdump-tree-optimized" } */
6 __attribute__((noinline
, noclone
)) char *
9 char *p
= r
? "a" : "bc";
10 /* String length for p varies, therefore strchr below isn't
12 return strchr (p
, '\0');
15 __attribute__((noinline
, noclone
)) size_t
21 /* String length is constant for both alternatives, and strlen is
26 __attribute__((noinline
, noclone
)) size_t
31 /* strcat here can be optimized into memcpy. */
33 for (i
= 0; i
< n
; i
++)
35 /* strcat here is optimized into strlen and memcpy. */
37 /* The strlen here can't be optimized away, as in the loop string
38 length of p might change. */
44 __attribute__((noinline
, noclone
)) size_t
50 char *p
= strchr (x
, '\0');
51 /* strcpy here is optimized into memcpy, length computed as p - x + 1. */
53 /* strcat here is optimized into memcpy. */
55 for (i
= 0; i
< n
; i
++)
57 /* strcat here is optimized into strlen and memcpy. */
59 /* The strlen should be optimized here into 4. */
61 /* This stays strcpy. */
72 if (memcmp (fn1 (l
) - 1, "a", 2) != 0)
74 if (memcmp (fn1 (!l
) - 2, "bc", 3) != 0)
76 if (fn2 (l
) != 1 || fn2 (!l
) != 3)
78 memset (b
, '\0', sizeof b
);
80 if (fn3 (b
, 10) != 4 || memcmp (b
, "aaaabcd", 8) != 0)
82 if (fn3 (b
, 128) != 7 || memcmp (b
, "aaaabcdabcdefg", 15) != 0)
84 if (fn3 (b
, 256) != 10 || memcmp (b
, "aaaabcdabcdefgabcdefgefg", 25) != 0)
87 || memcmp (b
, "aaaabcdabcdefgabcdefgefgabcd", 29) != 0
88 || memcmp (buf
, "aaaabcdabcdefgabcdefgefg", 25) != 0)
91 || memcmp (b
, "aaaabcdabcdefgabcdefgefgabcdabcd", 33) != 0
92 || memcmp (buf
, "aaaabcdabcdefgabcdefgefgabcdefg", 32) != 0)
95 || memcmp (b
, "aaaabcdabcdefgabcdefgefgabcdabcdabcd", 37) != 0
96 || memcmp (buf
, "aaaabcdabcdefgabcdefgefgabcdabcdefgefg", 39) != 0)
101 /* { dg-final { scan-tree-dump-times "strlen \\(" 5 "strlen" } } */
102 /* { dg-final { scan-tree-dump-times "memcpy \\(" 6 "strlen" } } */
103 /* { dg-final { scan-tree-dump-times "strcpy \\(" 1 "strlen" } } */
104 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
105 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
106 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
107 /* { dg-final { scan-tree-dump-times "return 4;" 1 "optimized" } } */