[InstCombine] Missed fold of ((y != 0) | y) in boolean context
Open
llvm:instcombine
missed-optimization
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following the expression can be simplified to:
`return y != 0;`
y is unsigned, so y > 0 is equivalent to y != 0.
```c++
bool x(unsigned long long y) { return (y > 0) | y; }
```
```llvm
define i1 @x(i64 %y) {
entry:
%gt = icmp ugt i64 %y, 0
%gt64 = zext i1 %gt to i64
%or = or i64 %gt64, %y
%result = icmp ne i64 %or, 0
ret i1 %result
}
```
expected
```llvm
define i1 @x(i64 %y) {
%result = icmp ne i64 %y, 0
ret i1 %result
}
```
https://godbolt.org/z/c4PEGWPxM
I don't expect this pattern to show up often but gcc for example realizes the y > 0 is unnecessary
https://godbolt.org/z/nKdPn7zTf
Contributor guide
Assessment
This issue has not been assessed yet.