This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/78809] Inline strcmp with small constant strings


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809

--- Comment #27 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
(In reply to Qing Zhao from comment #23)

> qinzhao@gcc116:~/Bugs/78809/const_cmp$ cat t_p.c
> #include <string.h>
> 
> char array[]= "fishiiiiiiiiiiiiiiiiiiiiiiiiiiiii";
> 
> #define NUM 1000000000
> int __attribute__ ((noinline))
> cmp2 (const char *p)
> {
>   int result = 0;
>   int i;
>   for (i=0; i< NUM; i++) {
>     result |=  strcmp (p, "fishiiiii"); 
>   }
>   return result;
> }
> 
> int result = 0;
> 
> int main()
> {
>   for (int i = 0; i < 25; i++)
>      result += cmp2 (array);
>   return 0;
> }

I don't think this is a good test.  Repeatedly calling strcmp with the same
inputs is not something real code does, especially when the string matches
exactly.  Why would it do that?  The consequence is that you are probably
optimizing for a very unlikely scenario.  Instead you need to look at traces
from real code to understand how strcmp is called in practice.  Nothing else
will give you a defensible answer.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]