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

    <tr>
        <th>Summary</th>
        <td>
            std::(ranges::)fill on spans does not optimize with -Oz
        </td>
    </tr>

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

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

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

<pre>
    `std::span` doesn't provide span-based methods for `memcpy`, `memset`, etc. I gather this is because we already have more general iterator- or range-based versions of these operations, so there's no need to duplicate the API surface when `std::fill`, etc., can just be specialized on contiguous iterators.

This works out nicely with `-O2`, where Clang and libc++ are able to dissolve the abstractions effectively. However, with `-Oz`, this doesn't happen and we get _larger_ code than with `-O2`!
https://godbolt.org/z/Eofzhfoqa

I assume this is because `-Oz`'s inlining heuristics are stop too early and it don't break down the abstractions that it's meant to break. Not sure if this should be fixed in libc++ or `-Oz` but, one way or another, this combination isn't great. Moving codebases to something like spans and ranges is a nice safety win, particularly combined with libc++ hardening mode, but the standard way to express this doesn't seem to work well with this combination.

CC @danakj
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxkVM1y4zYMfhr6grFHlv8PPiTZeppDuz30vgOJsMSEIlQCstZ--g4pN-smF2tImvx-8AEo4ppAdDSbZ7P5NsNBW45HixdnKwqziu31aLaFqDWrJ7N6kh6D2RZgmSSYcqfQR744S5BO5hUKWehIW7YCZ45gtkVHXd1fzbYw5ct9LaT3NWm9gFdoUFuKoK0TcAIV1TgIwUiAPhLaK7R4Ieg4EjQUKKIHpxRROc6BI0QMDd3xLxTFcRDgM2hLQsB9-mvaS5jCaTuSKXcCgSEQWVAGO_Te1aiUjuHpr1eQIZ6xJhhbCvDow9l5_6AgfWsM8DaIQpXMoNqhdzeywAFqDuqagQf5IC0LU3wzxdP0-3fSPXJ8F-BBIbia_BVGp21CnX8v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