select(fcmp nnan one, ...) optimization does not trigger when RHS is 0
Open
Nobody has claimed this yet.
llvm:instcombine
missed-optimization
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I observed that in LLVM, the pattern:
define float @src(float %x) {
%fcmp = fcmp nnan one float %x, 6.0
%fsub = fsub float %x, 2.0
%sel = select i1 %fcmp, float 2.0, float %fsub
ret float %sel
}
can be optimized to:
define float @tgt(float %x) {
%fcmp = fcmp nnan one float %x, 6.000000e+00
%sel = select i1 %fcmp, float 2.000000e+00, float 4.000000e+00
ret float %sel
}
However, when the right-hand side of the fcmp is 0, this optimization does not happen
define float @src(float %x) {
%fcmp = fcmp nnan one float %x, 0.0
%fsub = fsub float %x, 2.0
%sel = select i1 %fcmp, float 2.0, float %fsub
ret float %sel
}
This src will not be optimized to the following tgt
define float @tgt(float %x) {
%fcmp = fcmp nnan one float %x, 0.000000e+00
%sel = select i1 %fcmp, float 2.000000e+00, float -2.000000e+00
ret float %sel
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided @src LLVM IR through the relevant optimization pipeline and compare it with the @tgt form shown for the RHS value 6.0. Trace the fcmp/select optimization and verify that the same expected constant-folding result is produced when the comparison RHS is 0.0.
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
- 48/100