<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJytVl2vmzgQ_TXkxcIC85mHPCS9rbbqtnfVW-0rMjAJ3gCmtklu9tfvDGRvk96oarMboQDGPnN8Zjwzpa5Pq7VlBgZtHNRM9axxbrBetPbEO7wMHBQcLW_bQ8e12eHQQxiILMg8EUUizUSWe-INk1sHhuW1SLJUZCJI00CWMoriOEsEJFkmIQvCDNJQJJVg5ajaWvU75hpgaAQ2Tw_MS4NOugZN6AF6N5oeRxgxY0flGla1Eld4IpfWgnFK95ZBL8sWak8sWSVHC5Y14w5YB502JzZauQPO3mmDE2sfvxtLbF2jaNM7A4hUsxLcEaA_GwgFk33NwohmlqNjpbJQkTlmG320P79LpxF62uLEbdIJkWlgMBp5d-woLbNOtS2OgMVds2ODTN5PCjkmkWVFo51E11S665QjBao6D4UoRbbNt7h37gUPXrCe_z-PfU_SeskG9RvAbPHmJQ-47Nq39Ikf1V7xPZge2rN_VV_DMx-aAZ8_otniDxSRBEYBiLrcblEOlG2Wi0jRrmZtXCMdQ46or0UnTj5utbNMb5kZe6c6oCBDRmNv1a5HmCdncNZHObzvhpbIRevftd6Pw2as9uDQech8nvQZtuyT7IgNhQaZxftBq5sonzEIDvABTi_r8fPb3pnTRlpAGdd_zkA0_UJAGpmv6fVJIiKQbCxM4g-0EziQTzyRVaeKPomMfPt2Gq30OH3L5YBOfuZkgpZmCV7LKIjicMZ9PIBpQNaMvTlLyJ4aaVCRx_IvVJidf0-nrtTtvIbeheBJ4ImEzQ7wxAav84sfxuzyhzHA0fWMju8syk-o_WIpzHgav7bUqrLyBY9CbvUrS0WBZ490L-ThuRh72U5eLsB09gI54Zn4P_fwzdcvNljElzfYI9w53Peybe0JaSH4bGdPj3gQB3RDAc_KFU4XlDU6XcMVMjr115ExVqQpBjxO38nBBE-je4SuGkM6iysoys2_zK2XTqHTlPlaGKDci4_gLnBDnt6zZ9N9HWGEa6B73GJPfYXUdvYKKknvgAJjtCmAMsE1WHIPr6McdhaZWacxaohhgYf5XxVvB1DIxY0j_BP-7obJ3wVGe3kJGPDsHiX-lkMxOGSNi4ArayQPrlHvcdUWC3oxVANFui3Ksd3fTKzncgWYJutxLrAOVcRiibXyJSUnmwfUxe9UzxGRu2d3q5btsEEYS47FCF-mTDHffASnZIqvWzWl6nfZMkqWaUKdzPfAeKpvMIO5_UCbSN030MpnqH1MbNJiGqJChNXuoJxsWQMG5oT_g4Iy102_qkLmYybD4sKe87RIY99n_hN7ZYH5j4Jdcv2Bmp8ev7ylcrMBZkcD1IJg2WVWd4BNDxVjtYep_LaKegn_gPuKaWsiDzEk19jcxS-35bnQlrDVZu5kzKW7zrWfih-2WEfpquaq9ZqbmbkdMHNbQnMxuk96pEQ7VczHx4_-HlsgoofjBo-6ddBxztnk37NTFvUqqpfRUi7k6BptVg-0A3Na97VR1WI07eqXY0JZO05BkURxkC6aVRTmAWQyiUFElcyXSZwnS5HkIhYizPNg0coSWrui5kqIHo5sgsBnjMrFf2egViIQIsD-kboFEXABaZ6WpZCBhDyuYy8OAJvB9qUjX5jVBFmOmBrjoFXWfWvXF9gqU_2FiTAydMq1sPrt-x4Ze7LKAHVFrxp5ivsp_m923YuJ_2oi_w8Aw7fI>53406</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Huge memory usage increase after 8d257627206 (with assertions enabled)
        </td>
    </tr>

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

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

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

<pre>
    As reported in https://reviews.llvm.org/D102707#3267278, after 8d25762720660aba3344752e577ae7017e6125c2 building the FreeBSD `math/openturn` port with clang (assertions enabled) causes huge memory usage. For end-users, this regressed between clang 12 and 13, but bisection shows 8d25762720660aba3344752e577ae7017e6125c2 to be the cause, and the problem was still present when I built a recent main commit (cd8122b27f8f).

Running [`perf`](https://perf.wiki.kernel.org/index.php/Main_Page) on the affected clang command shows that it is spending lots of runtime in `unsigned StringMapImpl::LookupBucketFor(StringRef Name)` and `void StringMapImpl::RemoveKey(StringMapEntryBase *V)`:

```
Samples: 154K of event 'cycles', Event count (approx.): 175175930341
Overhead  Command  Shared Object        Symbol
    22.50%  clang++  clang-14             [.] llvm::StringMapImpl::LookupBucketFor
    17.64%  clang++  libc-2.31.so         [.] __memmove_avx_unaligned_erms
    15.72%  clang++  clang-14             [.] llvm::StringMapImpl::RemoveKey
     3.94%  clang++  [kernel.kallsyms]    [k] prepare_exit_to_usermode
     3.29%  clang++  [kernel.kallsyms]    [k] clear_page_erms
     2.63%  clang++  libc-2.31.so         [.] __memchr_avx2
     2.07%  clang++  [kernel.kallsyms]    [k] native_irq_return_iret
     1.69%  clang++  [kernel.kallsyms]    [k] rmqueue
     1.64%  clang++  [kernel.kallsyms]    [k] sync_regs
     1.56%  clang++  [kernel.kallsyms]    [k] error_entry
     1.55%  clang++  [kernel.kallsyms]    [k] swapgs_restore_regs_and_return_to_usermode
     1.20%  clang++  libc-2.31.so         [.] __memcmp_avx2_movbe
     0.76%  clang++  [kernel.kallsyms]    [k] zap_pte_range.isra.0
     0.74%  clang++  [kernel.kallsyms]    [k] free_pcppages_bulk
```

Reproduction test case:
[Dlib-min.cpp.txt](https://github.com/llvm/llvm-project/files/7935965/Dlib-min.cpp.txt)

Reproduce with (`-relaxed-aliasing` is vital here):

```
clang -cc1 -triple x86_64-- -S -relaxed-aliasing -O2 Dlib-min.cpp
```

NOTE: Be sure to run something like `ulimit -v $((10*1024*1024))` before the reproduction command, or watch memory usage when it is running, so you prevent OOM-killing your system... :)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVtuOm0gQ_Rr80qIFzc1-8IOdSbRRNplVZrWvqIGy6TXQpLvxZb9-q8A7sWesaMZaCxlo4NSpU9VVVejqtFxZZqDXxkHFVMdq53rrRStPfMLDwF7BwfKm2bdcmy0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