Repository navigation
Conversation
LLVM codegen hit an internal check on arithmetic over bool operands, while the C target builds the same function. Follow the C target: compute in int and convert back to bool, so a non-zero result is true. Fixes apache#20558 Generated-by: Claude Code (Claude Opus 5.5)
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20558.
+,-and*on bool operands hitCheck failed: (t.MatchesCode(DLDataTypeCode::kDLFloat))in the LLVM codegen, becauseDEFINE_CODEGEN_BINARY_OPonly handled int, uint and float. The C target builds the same function.This PR follows the C target. The bool operands are zero-extended to i32, the operation is done in i32, and the result is converted back to bool by comparing it with zero. For 0/1 inputs this gives OR for
+, XOR for-and AND for*, and in the optimized IR (inspect_source("ll")) the vectorized case reduces to exactlyor,xorandand. The same code path covers vector bool types.To check that the behavior matches, I built the same PrimFunc for
target="c", compiled it withexport_library, and compared the stored bytes with the LLVM build for all four input combinations. They are identical.In the issue I also asked whether bool arithmetic should instead be rejected earlier. I can switch to that approach if you prefer it.
Testing: added
test_llvm_bool_arithtotests/python/codegen/test_target_codegen_llvm.py. It covers all input combinations for+,-and*with both a serial and a vectorized loop. It fails on main with the check above and passes with this change. The fulltest_target_codegen_llvm.pypasses locally (381 passed).Generated-by: Claude Code (Claude Opus 5.5)