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] !a == (a < 0) is not optimized #67916

Closed
k-arrows opened this issue Oct 1, 2023 · 1 comment · Fixed by #68244
Closed

[InstCombine] !a == (a < 0) is not optimized #67916

k-arrows opened this issue Oct 1, 2023 · 1 comment · Fixed by #68244

Comments

@k-arrows
Copy link

k-arrows commented Oct 1, 2023

Consider the following functions:

int foo(int a)
{
   return !a == (a > 0);
}

int bar(int a)
{
   return (a < 0);
}

int baz(int a)
{
   return !a == (a < 0);
}

int qux(int a)
{
   return (a > 0);
}

Both Clang and GCC can optimize foo to bar. GCC can also optimize baz to qux, but Clang cannot.
https://godbolt.org/z/exvTE8Gn7
https://alive2.llvm.org/ce/z/LGvASc

@XChy
Copy link
Member

XChy commented Oct 3, 2023

The fold zext(icmp (A, xxx)) == shr(A, BW - 1) => not(trunc(xor(zext(icmp), shl))) would be a more convenient way to optimize it.
alive-tv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants