<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60165>60165</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            comparison with short (< 16 chars) local `const std::string` is slower when it is `static`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          firewave
      </td>
    </tr>
</table>

<pre>
    Split from #58002.

```cpp
#include <string>

#define LITERAL_S "012345678901234"
#define LITERAL_L "0123456789012345"

bool cmp3_s(const std::string& s)
{
 const std::string s_s(LITERAL_S);
    return s == s_s;
}

bool cmp4_s(const std::string& s)
{
    static const std::string s_s(LITERAL_S);
    return s == s_s;
}

bool cmp3_l(const std::string& s)
{
    const std::string s_s(LITERAL_L);
    return s == s_s;
}

bool cmp4_l(const std::string& s)
{
    static const std::string s_s(LITERAL_L);
    return s == s_s;
}
```
https://quick-bench.com/q/A3FPfNV6Cds2TwwBvSRwT6klxLg

This applies to all strings with less than 16 characters.

This does not happen with GCC where `static` is always faster no matter the length: 
https://quick-bench.com/q/hPor-y8JDwcMBEnT_oOv79nF43g
https://quick-bench.com/q/4Ef2dOfaBuhCd0QkKBRVVCXamjI
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8lN-PozYQx_8a8zLayNhgyAMP-Vldm_auu9Gqb5EBg31rbGqb0P3vK0jSu1NTaW9VnYSMGc-MPzNfY-69ao0QBUrXKN1GfAjSuqJRToz8LKLS1q_FU69VgMbZDhChaY4xWSC8RXh1HRm-PFXfXy2EKlPpoRaA6MYHp0yL6O6bIEJr0Sgj4PDhuHtcHU5PgAjBMaFJyrJ8Oc8QIf_lfrjjnn7xn8fSWg1V19OTRySvrPEBfKgRXSG6umIRBh6R5TUsW18mcNcZ_JzoH-Ipjt4iAMCJMDgDHhDdIrqd3W_rKNveQ0u-Hw0AfOBBVT8Mkp70OyDfQnf4X1r4HrrvaOE7IW-_xeVThtD7aROyR2T_56Cql4dSmEouKttNFkT2K7r_1Pz2zDa1J8dxXJ-fHscje9F_HdqvCz9K5YH3vVbCQ7DAtYYLuIdRBQlaeA9BcgMxg0pyx6sgnF_8K0lthQdjA0je98Jcon_abGCUwglADF_ahBiGaU898lcPDfdBODAWOh6mWZACtDBtkIiu4O31yk_WPbzmP2_H6tf1zhxP9uM5W5p9Qtu3J0l2Dak_Nnw9yE2Nf3_5Zf34_Lz5g3efP0R1QeslXfJIFDHLEkJinMSRLBjLMypiluUU11lKljQXdblMqrTJGsqaSBUEE4pjgmNKEhwvmqxhuCypaNIk5yRGCRYdV3qh9blbWNdGyvtBFAzHLI00L4X2861KiBEjzIvT7ZRuI1dMMQ_l0HqUYK188F-yBBW0KCrb9dwpb6-SeGldAERyRDc3TadzDdpWXE863T_-F9m8tqNwk6YGVJgsXwsbDU4X3za6VUEO5bXHE9r19dA7-1lUAZH9XJBHZD8X_HcAAAD__3MM2Co">