[Bug tree-optimization/103798] memchr with a (small) constant string should be expanded inline.

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Dec 22 07:24:32 GMT 2021


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |tree-optimization
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement
            Summary|Missed optimization:        |memchr with a (small)
                   |char_traits<char>::find     |constant string should be
                   |(and thus                   |expanded inline.
                   |string_view::find_first_of) |
                   |is slow when invoked with   |
                   |short strings               |
   Last reconfirmed|                            |2021-12-22

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Really the issue is:
  _8 = __builtin_memchr ("eE", _7, 2);
  if (_8 != 0B)


Should just be expanded to _7 == 'e' || _7 == 'E' .

That is:
int f(char a)
{
   return  __builtin_memchr ("e", a, 1) != 0;
}
int f1(char a)
{
   return a == 'e';
}
int g(char a)
{
   return  __builtin_memchr ("eE", a, 2) != 0;
}
int g1(char a)
{
   return a == 'e' || a == 'E';
}

f and f1 should produce the same assembly
and g and g1 should produce the same (similar) assembly.


More information about the Gcc-bugs mailing list