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

    <tr>
        <th>Summary</th>
        <td>
            -Oz larger than -Os
        </td>
    </tr>

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

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

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

<pre>
    I have a simple loop that seems to use more instructions under -Oz than it does under -Os.

```
% cat tinysum.c 
int sum(const unsigned char * const buffer)
{
    int s = 0;
    for (int i = 0; i < 100; ++i)
        s += buffer[i];
 return s;
}
```

compile with clang -c tinysum.c -Os or -Oz

```
% otool -tV tinySumO?
tinySumOs:
(__TEXT,__text) section
_sum:
0000000000000000        mov     x9, #0x0
0000000000000004        mov     w8, #0x0
0000000000000008        ldrb    w10, [x0, x9]
000000000000000c        add     w8, w8, w10
0000000000000010        add     x9, x9, #0x1
0000000000000014        cmp     x9, #0x64
0000000000000018        b.ne    0x8
000000000000001c        mov     x0, x8
0000000000000020        ret
tinySumOz:
(__TEXT,__text) section
_sum:
0000000000000000        mov     x9, #0x0
0000000000000004        mov     w8, #0x0
0000000000000008        cmp     x9, #0x64
000000000000000c        b.eq    0x20
0000000000000010        ldrb    w10, [x0, x9]
0000000000000014        add     w8, w8, w10
0000000000000018        add     x9, x9, #0x1
000000000000001c        b       0x8
0000000000000020        mov     x0, x8
0000000000000024        ret
```

happens with
```
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
```

though testing with godbolt shows it happening all the way from 9 through 20.

GCC seems to generate identical code for both optimization settings.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVUGPszYQ_TXOZQQyNiRw4LBJmqqnPXRV9RYZmIArg6ltkuz--somm-xWfP12b0WRY2aen8fzzIywVrYDYkmyLcn2KzG5Tpvy6vT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