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

    <tr>
        <th>Summary</th>
        <td>
            Constructors with bitfields do not properly combine loads and stores
        </td>
    </tr>

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

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

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

<pre>
    Compiler Explorer link: https://gcc.godbolt.org/z/8oKcoY8b8

This is a very reduced test case from some code in Chromium:

```c++
class C {
 public:
    C(const C& other);

    unsigned a : 17;
    unsigned b : 15;
};

// Terrible code when not inlined
C::C(const C& other)
    : a(other.a),
      b(other.b) {}

// Good code when inlined
C copy(const C& other)
{
    return other;
}
```

When compiled with Clang 19 and -O2 (on x86-64), this generates terrible code the first case; there are multiple loads and stores, the compiler tries to preserve existing bit values and then throw them away etc.. (It almost looks like some kind of aliasing issue or something?) However, if inlined, as in the `copy()` function, the problems mysteriously go away.

GCC has no issue; it generates basically the same code for both cases.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VE-PqzYQ_zTOZbQITBLCgUOWbV6rHnp5UtWjbQZw13iQxySbfvrKkN3u9ulJSCEM_v3zDytmO3jERhyexeFlp5Y4UmgYmXGnqbs3LU2zdRjgl7fZUcAAzvpXUZ5hjHFmUZ6FvAh5GYzJBuo0uZhRGIS8_CPk5US_G_rrpE8iP4v8_H20DJZBwRXDHQJ2i8EOInIEoxihDzQB04RgqEOwHtox0GSXKRGtGOKYb5cR8jld-dk4xQwtiCr9g3nRzpptAQBAK-TJkOeY7o5AccQgZC3K5w0xvbP4NYgOFCRvRbVNv4z0Njo8FlYvHwhbBPAdQ7DaPcTfRvTgKYL1znrsRH5uk6jy_DNBG18iUUKe1seZSgPZPmYA-mOihaxXy9XLFxXfiLpPCj6xg6H5_lPuR3oAEDAuwT9mH2Y_Rb_x_ZngzdaPDm42jtA65QcoalC-g6c_JCS1Ht5Ox6fjfnMCMZVgQI9BRWSIX0KLI0Jvw6MPonxOTwKCCgjT4qKdHYIj1fFKwZEC8oaK71oCxGATMsEckDFcEfDNcrR-AG0jXJVbcAOIyUMcA93S7QTqpu6A0WRZkv5bBOUm4giO6JXB2Vfc6vlqfQfUg3JWccK1zAsChXUcR-sHUV7SDv1KN7ymjFuw_cduyBYUp34n3anM286kiI459Is30ZJ_NzYH0g4nhunOEYOlhd0dBlrlZttufGtbGBWDp01Lys7GT0FrxdYo5-4rJKv3j6ynAJriuCbO2a5ryq4ua7XDpqjKUy2Lqip2Y1MXqPtDpWS-N4e9kdWpy3Wt66Lste7remcbmctDLvMqr_d1WWQ635-OR50XKI3pUYl9jpOyLnPuOqVTYrcqbQp5lIXcOaXR8XoUSenx9vAhZTqZQpMWPellYLHPneXI_8FEGx02bap1WEykwFsdtY29RdcxdLR-inOgGYO7p6po63-s0m4JrvnfyWbjuOjM0CTkJVE-fp7mQH-jiUJeVqEs5OXh5NrIfwMAAP__waqy0w">