Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstCombine should fold frexp of select to select of frexp #92542

Open
arsenm opened this issue May 17, 2024 · 12 comments · May be fixed by #121227
Open

InstCombine should fold frexp of select to select of frexp #92542

arsenm opened this issue May 17, 2024 · 12 comments · May be fixed by #121227
Assignees
Labels
floating-point Floating-point math good first issue https://github.com/llvm/llvm-project/contribute llvm:instcombine missed-optimization

Comments

@arsenm
Copy link
Contributor

arsenm commented May 17, 2024

If one of the select operands is a constant, we generally push operations through to select on the result.

define float @src(float %x, i1 %bool) {
  %select = select i1 %bool, float 1.000000e+00, float %x
  %frexp = tail call { float, i32 } @llvm.frexp.f32.i32(float %select)
  %frexp.0 = extractvalue { float, i32 } %frexp, 0
  ret float %frexp.0
}

define float @tgt(float %x, i1 %bool) {
  %frexp = tail call { float, i32 } @llvm.frexp.f32.i32(float %x)
  %frexp.0 = extractvalue { float, i32 } %frexp, 0
  %select = select i1 %bool, float 5.000000e-01, float %frexp.0
  ret float %select
}

This case is somewhat complicated by the extractvalue. The combine should be rooted at a hasOneUse extractvalue (frexp), 0

@arsenm arsenm added good first issue https://github.com/llvm/llvm-project/contribute llvm:instcombine missed-optimization floating-point Floating-point math labels May 17, 2024
@llvmbot
Copy link
Member

llvmbot commented May 17, 2024

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor has already been assigned to this issue. If you believe that no one is actually working on it despite an assignment, ping the person. After one week without a response, the assignee may be changed.
  2. In the comments of this issue, request for it to be assigned to you, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvmbot
Copy link
Member

llvmbot commented May 17, 2024

@llvm/issue-subscribers-good-first-issue

Author: Matt Arsenault (arsenm)

If one of the select operands is a constant, we generally push operations through to select on the result.
define float @<!-- -->src(float %x, i1 %bool) {
  %select = select i1 %bool, float 1.000000e+00, float %x
  %frexp = tail call { float, i32 } @<!-- -->llvm.frexp.f32.i32(float %select)
  %frexp.0 = extractvalue { float, i32 } %frexp, 0
  ret float %frexp.0
}

define float @<!-- -->tgt(float %x, i1 %bool) {
  %frexp = tail call { float, i32 } @<!-- -->llvm.frexp.f32.i32(float %x)
  %frexp.0 = extractvalue { float, i32 } %frexp, 0
  %select = select i1 %bool, float 5.000000e-01, float %frexp.0
  ret float %select
}

This case is somewhat complicated by the extractvalue. The combine should be rooted at a hasOneUse extractvalue (frexp), 0

@isakhilesh
Copy link

Hello,
Can this issue be assigned to me, I want to work on this?
Thanks

@akielaries
Copy link
Contributor

@isakhilesh are you still working on this?

@isakhilesh
Copy link

@isakhilesh are you still working on this?

Hey, yes I am working on the issue.

@Verylostpenguin
Copy link

Hi @isakhilesh, are you still working on this? What progress have you made?

@Verylostpenguin
Copy link

As @isakhilesh doesn't seem to be working on the issue anymore, can I be assigned the issue instead?

@vortex73
Copy link
Contributor

vortex73 commented Oct 22, 2024

Hey this looks intriguing! Unless someone is still working on it could it be assigned to me?

@vortex73
Copy link
Contributor

vortex73 commented Nov 2, 2024

So just to be clear, we aim to implement 3 things:

  • Replace the frexp with select between frexps
  • Compute frexp of constants at compile time
  • Check that extractvalue instr are used only once

and concerned source files are InstCombineSelect.cpp and InstCombineMulDivRem.cpp
Have I misinterpreted anything?

@whiteio
Copy link
Contributor

whiteio commented Dec 18, 2024

Hi is anyone working on this? I'd like to if not

@arsenm
Copy link
Contributor Author

arsenm commented Dec 19, 2024

So just to be clear, we aim to implement 3 things:

  • Replace the frexp with select between frexps

There is only a single frexp in the source and result, but logically yes. This shouldn't be done if one of the frexps doesn't fold away

and concerned source files are InstCombineSelect.cpp and InstCombineMulDivRem.cpp

Yes

@vortex73
Copy link
Contributor

Hi is anyone working on this? I'd like to if not

Yes I am.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
floating-point Floating-point math good first issue https://github.com/llvm/llvm-project/contribute llvm:instcombine missed-optimization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants