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

    <tr>
        <th>Summary</th>
        <td>
            memcpy/memset not inlined when __builtin_assume gurantee the data is short enough
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:optimizations,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    The code below is in apache arrow cpp[1]. The arrow-rs also has similiar phenomenon[2].

To be short, when size is gurantee to be less or equal to `12`, gcc would inline the `memcpy` and `memset`
but the clang don't optimize this. See godbolt link [3]. The problem is still exists when `-ffreestanding` is enabled.

```c++
c_type makeInline1(const char* data, int32_t size) {
  ARROW_COMPILER_ASSUME(size <= kInlineSize); // __builtin_assume
  c_type out;
  out.inlined = {size, {}};
  // Memcpy for 0 to 12
  memcpy(&out.inlined.data, data, size);
  return out;
}
```

Would this being a problem? If it can be fixed with some compiler flags, what flag should I use?

[1] https://github.com/apache/arrow/blob/63b34c97c5d3ca6d20dacb9e92b404986f1d7d62/cpp/src/arrow/util/binary_view_util.h#L28
[2] https://github.com/apache/arrow-rs/issues/6034
[3] https://godbolt.org/z/47T8s69xK
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVN1u2zgTfZrxzSAGRf1YvtCFnVRA8LXohyZFLw1SHEncUqRWpOokT7-gZKfOYrHAAoQlU_NzZs7MEd7rzhJVkB-BcxWal7fXM3AO-cNGzKF3UzWI0VD9fSOdeq2ee8LGKUJJxp1Re9QWxSianlBMkztjM46QHxPIH7b4fL29mzwK4x32wqPXgzZaTDj2ZN1A1lnIjzHlFtgDsMP6--xQEvreTQH4PZ57suj1G8Wk3TwJG4gwLEaGvEc3If05CxPvoGAJh4JFx65p8Oxmo1Bboy1h6CkaDDQ04ysUDIV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