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

AND with == 0 and OR with != 0 #68799

Open
k-arrows opened this issue Oct 11, 2023 · 0 comments · May be fixed by #69840
Open

AND with == 0 and OR with != 0 #68799

k-arrows opened this issue Oct 11, 2023 · 0 comments · May be fixed by #69840

Comments

@k-arrows
Copy link

It was difficult to title the issue. Feel free to modify it appropriately.

Consider the following functions:

bool f_and(int x,int y)
{
  bool a = x == 0;
  bool b = y == 0;
  bool t = a & b;
  return t & !a;
}

bool f_or(int x,int y)
{
  bool a = x != 0;
  bool b = y != 0;
  bool t = a | b;
  return t | !a;
}

The function f_and can be optimized to 0, and f_or can be optimized to 1.

https://godbolt.org/z/nWq194nz9
https://alive2.llvm.org/ce/z/PPCfP9

FYI (original issue)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111542

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