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

    <tr>
        <th>Summary</th>
        <td>
            Assignment in expression with short-circuiting not optimal
        </td>
    </tr>

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

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

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

<pre>
    Given the following code:

```c++
#include <utility>

bool assignment_in_expr(bool& value)
{
    return value && !(value = false);
}

bool regular(bool& value)
{
    bool old = value;
    value = false;

    return old;
}

bool exchange(bool& value)
{
    return std::exchange(value, false);
}
```

Clang (trunk) with `-O3` produces ([godbolt](https://godbolt.org/z/477cMY6nh)):

```asm
assignment_in_expr(bool&):
 movzx   eax, byte ptr [rdi]
        cmp     al, 1
        jne .LBB0_2
        mov     byte ptr [rdi], 0
.LBB0_2:
 ret

regular(bool&):
        movzx   eax, byte ptr [rdi]
 mov     byte ptr [rdi], 0
        ret

exchange(bool&):
 movzx   eax, byte ptr [rdi]
        mov     byte ptr [rdi], 0
 ret
```

Function `assignment_in_expr` should produce the same assembly as the other 2 variants.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyklM9v6ygQx_8afBk1MuAfycGHplnvZVcr7W1PFYapzXsYIsBp-_76FY6TpklVZbWRFSRmvjMfhmFECLq3iA0pt6TcZWKKg_PN36LHn9r266xz6r35XR_QQhwQXpwx7lXbHqRTSPgjyXckP_1X-fGThG3Td9xlXFtpJoVA-NMUtdHxnfDfLpWdcwaOLCPa-KztM77tPWHrZCGsgoMwExK2WVT1EhwAwGOcvD16AGFVcieMErZetvgOXoQJs5yfqOrdDYDHfjLizqyzwhk1hz_68Qvzdepz3mtsZ9S3UPgmB2F7_E-1CFGlu-GPF-pF9fRdLU4XeEnxZITtgbB19JP9SdgGXnUcgFT5w1-cVDnsvVOTxJB8SLntneqciaTcEbYeYtyHhMJawtrFtHK-J6z9RVhb1LX885_KDoknIX3dUCKMx53veuRSD6M7_HoDABRv6czde0TYRw-k3HqlE9y5Zuknx_28CpO86WfjD4uw-mO7zZ_ZZ8PoDvP6RXT2BEsVT8ozmsd4ecibrvt0jo9Mdx3nLqJT0CuQ2077PxW9j-QD4avWaycro3YW5ha4ufkqhzC4yahTC84jKogR0yzBsTPvIMK86eKAHhgchNfCxrDKVMPVhm9Ehg2tOWW8rPM6GxpadEoKyTml2NUvJRacKlFJxaTsFJWZbljOCkppTvNizepV90JFvalyTsu6rsuOFDmOQpuVMYcx9XqmQ5iwobSsik1mRIcmzAOXMYuvMFsJY2n--iaJHrqpD6TIjQ4xfISJOhpsHs-FAG0hFQJDSEWan2UYnI8PUns56ZjmtHUR3D7qUZhs8qa5epE6DlO3km4krE2JluVh790PlJGwdsYLhLUL_6Fh_wYAAP__TzfKHQ">