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

Simplify applying bitwise operators on sign extended values #1111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

can-leh-emmtrix
Copy link
Contributor

Since the result of comparison and logical operators in C is of type int, complex logical expressions may result in expression trees where sext, extract and logical operators are used together (especially when the programmer uses temporary variables of type int to store boolean values and instcombine has not been executed).

This PR introduces the following simplifications for bit vectors of the same width a and b:

sext(a) & sext(b) -> sext(a & b)
sext(a) | sext(b) -> sext(a | b)
sext(a) ^ sext(b) -> sext(a ^ b)
~sext(a) -> sext(~a)

The pattern extract(sext(x), ...) is already handled by the existing simplifications.

If this breaks other important cases, it might be possible to enforce that a.bits() = b.bits() = 1, although I have personally seen a major impact anywhere else yet.

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

Successfully merging this pull request may close these issues.

1 participant