https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115474
Bug ID: 115474
Summary: Missed optimization: fold `std::max(a > b, a)` to `a`
(bool a, bool b)
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zhiwuyazhe154 at gmail dot com
Target Milestone: ---
godbolt example: https://godbolt.org/z/KG1fhaPvM
Code Example:
```
int func(bool a, bool b) {
return std::max(a > b, a); // equals to a
}
```
In this case, when a == 0, a > b == 0(a); when a == 1, a > b <= 1(a). So it can
be folded to a.
GCC -O3:
func(bool, bool):
cmp sil, dil
setb dl
cmp dl, dil
setb al
or eax, edx
movzx eax, al
ret
Expected code(CLANG -O3):
func(bool, bool):
mov eax, edi
ret