InstCombine misses redundant fcmp/select clamp for uitofp nneg
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This seems to be an InstCombine missed optimization related to #173452.
The `sitofp i8` form is optimized by:`-passes=instcombine`
```llvm
define float @src1(i8 %x) {
%f = sitofp i8 %x to float
%cmp = fcmp oge float %f, 1.270000e+02
%sel = select i1 %cmp, float 1.270000e+02, float %f
ret float %sel
}
```
It is folded to:
```llvm
define float @src1(i8 %x) {
%f = sitofp i8 %x to float
ret float %f
}
```
However, the following `uitofp nneg` form is not optimized:
```llvm
define float @src2(i8 %x) {
%f = uitofp nneg i8 %x to float
%cmp = fcmp oge float %f, 1.270000e+02
%sel = select i1 %cmp, float 1.270000e+02, float %f
ret float %sel
}
```
godbolt Link:https://godbolt.org/z/jcq67jrrG
Contributor guide
Research direction
Start in the InstCombine pass and reproduce the difference between the `sitofp i8` and `uitofp nneg i8` LLVM IR examples using the Godbolt link or the shown input. Compare the generated results and add a regression test for the redundant `fcmp`/`select` clamp, with the `uitofp nneg` form folding like the `sitofp` form.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100