| Issue |
115649
|
| Summary |
Assignment in _expression_ with short-circuiting not optimal
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Rageking8
|
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs