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

[CIR] Enable cir.bool binops #1312

Merged
merged 1 commit into from
Feb 6, 2025
Merged

Conversation

andykaylor
Copy link
Collaborator

Add !cir.bool to the list of types accepted by the binop rewriter. Although we don't generate boolean binops from logical operations on C++ boolean values, there will be cases where such operations are useful while generating conditions for other operations, such as the overflow checks needed for array new handling.

Add !cir.bool to the list of types accepted by the binop rewriter.
Although we don't generate boolean binops from logical operations on
C++ boolean values, there will be cases where such operations are
useful while generating conditions for other operations, such as the
overflow checks needed for array new handling.
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing wrong with using plain CIR checks, but if these pieces change we'll have to rewrite this testcase. Either (a) put the original C source in a comment or (b) write the test C -> LLVM IR directly (btw, we usually avoid writing LLVM IR dialect checks because for parity with LLVM IR, it's easier to compare the final IR with OG).

@andykaylor
Copy link
Collaborator Author

Nothing wrong with using plain CIR checks, but if these pieces change we'll have to rewrite this testcase. Either (a) put the original C source in a comment or (b) write the test C -> LLVM IR directly (btw, we usually avoid writing LLVM IR dialect checks because for parity with LLVM IR, it's easier to compare the final IR with OG).

I'm not sure it's possible to generate these cases from C/C++. If I have code like this:

bool f(bool a, bool b) {
  return a || b;
}

we generate a bunch of cir.ternary (presumably because the semantics for the || operator mean that the rhs expression might not be evaluated. That seems like something we may want to reevaluate at some point, but that the way it is now.

The reason I put up this PR is that when I implemented the array new support for the case with a variable array size, I needed to generate a binop or for the overflow handling, but the assert I'm modifying here rejected it during lowering. I threw in and and xor here just because they seemed logical to test.

@bcardosolopes
Copy link
Member

Gotcha, thanks for the further explanation, LGTM

@bcardosolopes bcardosolopes merged commit 95a497b into llvm:main Feb 6, 2025
7 checks passed
lanza pushed a commit that referenced this pull request Mar 18, 2025
Add !cir.bool to the list of types accepted by the binop rewriter.
Although we don't generate boolean binops from logical operations on C++
boolean values, there will be cases where such operations are useful
while generating conditions for other operations, such as the overflow
checks needed for array new handling.
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.

2 participants