<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJylVk2P2zYQ_TXyhbBhS_baPviwydboFkhSFAF6DCiRlphQpMoPO86v7xvSH1onPXVhrCxTM_PmzZsZ1Vacd10Igy-q56Lc4-PkUcmTn2l97GfWtfjpZTGfb9ZbxoWQgvmeu-BZsIwbYwMPkoVOsm_GngzjWtuGB-vYIZomKGs8O6nQ4UC1ppcmMGUO1vWczhivbQxkrhxzMkRn2JHrKP2Msc-d8qzjnjU8esRtrJCslUa6bOtk66T3KQRuv2-evjwtmVYmfmf-7IPsAbLjgcE6Ifwq-wSPFeWGG8H66HVRIeftHTYFfp3JGXtLSh3bH0prPuttvmZifGdPX3A2a1oFT0oU1ctivVwsV0v4-btTOke-YHt-98r8IBt1UNKPYhKScM1_8TStz-A0EYa0B6tMkM4X5Xv4sl6ODU8AczXc_NoO2e7V4YD_CYpXPySrpTLt1Q-eBdEbRjWTJ-kYuSEe_rjyJawkKvEUKscG6VIBTSMRmnvifzplKtwc4jlne8aBwWpmD0xI4_WZDbz5hmgXoLb-KpuQ8jp1qulYq44wJT9sNS_KFetlb92ZeX4kuEDvkB4K52Pt5T-RxNTwpqND1Q_OHiUJjCoIyKYo1yGp8g1iE_s6s7K56aGNZ5-FUMxfivlz_v_KTjZqAbJYYlL6RJUBWohq7FOAX5zTV-597AnQtYy4UX3sR_on9UGxw2BJ1WijzAfJEDKmGo0KnDlpNDfQ29o_NgHl6i_M-AgOBQ-cUhnlUazePfBx6s7UFC5761XbBXbigEY9fakhihAAB8XbsHG5UgE6fiRShDoqEbm-VvQmOfgBpp5KW6f-BmF8GCTPZ3XuioZ7OXsg_dmcT_xMhqOkWxk-ytMzMUjsXQ72yjQ6ChC3v_7yjnvV4PqZO9i8YtDMOuIVyhW2iUQ_Ud6h8c_U2ykkY7nHqUP-yq1E6DT58GFUOBJ_VioH2SrwWp-n1E_iyhqNJZp2PztGHhSwerYDlQ6ejDwhFzL_EoiEck0diEsWJd0Ddhu5Q2VkVgo0LiKp7OcAjXUO9QGihwEwG9P70QbVZPaJ2f9KgoI3qDGnZvpNkb6ol5G-dUIR1e8J7LguwIplcMdLPeApFZi-pfD-6zVcGrpZVOSDR6FCxpOQQqqehDgOBzK8hAYP9AQmC7oT5U2PpwVCeDhIgUYpAjR6Q0bIEeYNL9cNByusrbuVpkbJw4ePpED5Y_1wJzQ2EGG7jVZ8vyf2JsbrmwySsK-izMpBcEg61zFPe2loHOYxhHT7h-1mSBbeIm_MSSSfVD-9bJiGYR46p4RMIxbTxivUmjWY2SGNf5JA3kzT_adP0-SbKh-cGjRWIPXa64ffP-XJwkmxl7P7ZPRc_NTCGqoziHGUOnXyxTKho5IcVEuhcfdBmREfmeS8zdJQ-8XwvFVxRug2NI7TYqJZkrrofRpQeeXzLLjLawoJDaMxpfWndB0faAd7i4iG9_JRXgSPf7_Dg2PaGmvKZSSE1KW8r1UbbfSXCY7olxrltTIRu0psqy2f8Igd7naRCOq4mUSnH96_WrRbrGeNxfjc00vY5TJF839NytgrLBmq6n5VrZbzSbdb8ychKnFYrlaLFd9u8Lety_niUG62y2peTzSvpfY7rIKiLCmD5ALfi9XL5P8jULtyXuIzLxeL1XZezeqqlpWQ5dNTvakW20OxnGPZKn17q5y4XXKJlyePQ618uL9yTrBFaYbJBBgIgwpa7i7b-i6G0RvgJCHaJTj_Ak2gtxA>53540</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            malloc alignment regressions
        </td>
    </tr>

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

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

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

<pre>
    https://reviews.llvm.org/D100879 added smarts to annotate the known allocator functions with alignment information about their return values.  This has caused code generation regressions on x86_64 linux systems that use the jemalloc (and musl?) allocators.  I.e. https://bugzilla.mozilla.org/show_bug.cgi?id=1741454.  While the x86_64 ABI specifies allocators must return 16-byte aligned pointers, those allocators will return 8-byte aligned pointers /iff/ the size being allocated is 8 or fewer bytes.  Jemalloc does this for performance reasons -- it allocates from a pool of densly packed 8-byte objects, which gives it a 50% memory saving there and subsequent caching improvement.  I don't know performance numbers (jemalloc guys?)

I would be interested in what performance difference assuming 16-byte minimum alignment (as opposed to 8-byte) on the allocators gives clang's code generation.  Is there such data?

[I don't know why user code might want to allocate a ton of 8 byte objects and have individual 8-byte pointers to them, but that appears to be the case.)

Anyway,  clang's getNewAlign (clang/include/clang/Basic/TargetInfo.h) is documented thusly:
  /// Return the largest alignment for which a suitably-sized allocation with
  /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a
  /// correctly-aligned pointer.

Notice the 'suitably-sized allocation' caveat.  Either poor wording, or getNewAlign is not guaranteeing smaller alignment for smaller allocations.  I have not audited all the uses of getNewAlign to see if they presume the value is a conditional guarantee or not.

D100879 is unconditionally using that alignment, regardless of the size of allocation.

If getNewAlign's documentation is incorrect, then it would seem linux systems need some more target-specific overrides, possibly creating a 'x86_64-FOO-linux' triple.  (IMHO such a new triple would be sad.)

Alternatively, a new target config 'getMinNewAlign' that returns the minimum alignment guarantee. (8 in this case), and use that for annotations?  (Perhaps also rename getNewAlign to getMaxNewAlign, as 'new alignment' is ambiguous on these systems?)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx1VtuO2zgM_RrnRUiQ60zmIQ_TzgY7C7RdLAr0saAtxVYrS1ldkqZfv4dSLp60CwRxHJnk4eEh6drJ06aLcR-qxXM13-Lj1UGrY5gYc-gnzrf462U2na4fnwRJqaQIPfkYRHSCrHWRohKxU-K7dUcryBjXUHRe7JJtonY2iKOOHQ50a3tlo9B253xPfCaodimyufbCq5i8FQcySYWJEJ87HURHQTSUAuI2TirRKqt8sfWq9SqEHAK3P9YPXx-WwmibfohwClH1ANlRFLDOCL-pPsMT1XxNVoo-BVMtkPPTDTYHfp2oiXhLSp3an9oYmvSuXAsx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