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

clang cannot simplify (a gt/lt b) != (a le/ge b) where b is a specific constant #70928

Closed
k-arrows opened this issue Nov 1, 2023 · 1 comment · Fixed by #76334
Closed

clang cannot simplify (a gt/lt b) != (a le/ge b) where b is a specific constant #70928

k-arrows opened this issue Nov 1, 2023 · 1 comment · Fixed by #76334

Comments

@k-arrows
Copy link

k-arrows commented Nov 1, 2023

Example:
https://godbolt.org/z/7PMr8vc98

bool foo(int a)
{
   return (a > 5) != (a <= 5);
}

bool bar(int a)
{
   return (a < 5) != (a >= 5);
}

When checking this simplification with alive2, is it okay to try to represent an integer that is 1 greater than or 1 less than a certain integer using add or sub as follows?
https://alive2.llvm.org/ce/z/iddeDw

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 1, 2023
@k-arrows k-arrows changed the title clang cannot simplify (a gt/lt b) != (a le/ge b) where be is a specific constant clang cannot simplify (a gt/lt b) != (a le/ge b) where b is a specific constant Nov 1, 2023
@dtcxzyw dtcxzyw added missed-optimization and removed clang Clang issues not falling into any other category labels Nov 1, 2023
@dtcxzyw
Copy link
Member

dtcxzyw commented Nov 1, 2023

I guess #69840 may help. I will take a look later.

@dtcxzyw dtcxzyw self-assigned this Nov 1, 2023
dtcxzyw added a commit that referenced this issue Dec 24, 2023
This patch folds xor of icmps into a single comparison using range-based reasoning as `foldAndOrOfICmpsUsingRanges` does.
Fixes #70928.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment