Skip to content

missed fold, fcmp ogt (x - y), 0 => fcmp ogt x, y #85245

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

Closed
zhengyang92 opened this issue Mar 14, 2024 · 5 comments · Fixed by #85506
Closed

missed fold, fcmp ogt (x - y), 0 => fcmp ogt x, y #85245

zhengyang92 opened this issue Mar 14, 2024 · 5 comments · Fixed by #85506
Assignees
Labels
floating-point Floating-point math good first issue https://github.com/llvm/llvm-project/contribute llvm:instcombine missed-optimization

Comments

@zhengyang92
Copy link
Contributor

https://alive2.llvm.org/ce/z/azHAHq
https://godbolt.org/z/M8WbdYE8x

define i1 @src(float %0, float %1) {
%t2 = fsub float %0, %1
%t3 = fcmp ogt float %t2, 0.000000e+00
ret i1 %t3
}

define i1 @tgt(float %0, float %1) {
%olt = fcmp ogt float %0, %1
ret i1 %olt
}

@jayfoad @regehr

@dtcxzyw dtcxzyw added the good first issue https://github.com/llvm/llvm-project/contribute label Mar 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 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. In the comments of the issue, request for it to be assigned to you.
  2. Fix the issue locally.
  3. 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.
  4. Create a Git commit.
  5. Run git clang-format HEAD~1 to format your changes.
  6. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation.

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 Mar 14, 2024

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

Author: Zhengyang Liu (zhengyang92)

https://alive2.llvm.org/ce/z/azHAHq https://godbolt.org/z/M8WbdYE8x
define i1 @<!-- -->src(float %0, float %1) {
%t2 = fsub float %0, %1
%t3 = fcmp ogt float %t2, 0.000000e+00
ret i1 %t3
}

define i1 @<!-- -->tgt(float %0, float %1) {
%olt = fcmp ogt float %0, %1
ret i1 %olt
}

@jayfoad @regehr

@dtcxzyw dtcxzyw added the floating-point Floating-point math label Mar 14, 2024
@SahilPatidar
Copy link
Contributor

@dtcxzyw, I would like to take this one.

@jayfoad
Copy link
Contributor

jayfoad commented Mar 19, 2024

This only works for floating point formats that have IEEE-like denormals (does LLVM currently support any formats that do not have denormals?), and when denormals are not being flushed to zero. Otherwise you can have two different values x and y where x - y evaluates to 0.

@jayfoad
Copy link
Contributor

jayfoad commented Mar 19, 2024

As a follow up we could do the same kind of thing for plus, e.g. fcmp (x + y), 0 => fcmp x, -y, if either x or y can be negated for free.

SahilPatidar added a commit to SahilPatidar/llvm-project that referenced this issue Mar 22, 2024
SahilPatidar added a commit to SahilPatidar/llvm-project that referenced this issue Apr 17, 2024
SahilPatidar added a commit to SahilPatidar/llvm-project that referenced this issue Apr 25, 2024
dtcxzyw pushed a commit that referenced this issue Jun 29, 2024
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this issue Jul 3, 2024
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.

5 participants