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

[VAN-503] Convert to/from i1 as needed #47

Merged
merged 5 commits into from
Aug 18, 2023
Merged

[VAN-503] Convert to/from i1 as needed #47

merged 5 commits into from
Aug 18, 2023

Conversation

iangneal
Copy link

The logic functions (fr_logic_*), the library functions (like constraints and assertions), and branch instructions require i1 (i.e., boolean) arguments. So, when storing the results of logic operations to a regular variable (which is always a bigint, i.e. i256) or implicitly converting a regular variable into a boolean (e.g., if (foo)), a conversion needs to occur in the LLVM IR. I've implemented the following changes:

  • When creating a call, store, or return with boolean arguments, automatically add a conversion to boolean if the provided argument is a non-boolean integer (by adding a computation of val != 0).
  • When creating a call, store, or return with an integer argument, automatically add a conversion to the non-boolean integer if the provided argument is a boolean (by adding a zext instruction).
  • When creating a branch, ensure that the value is converted to a boolean using the above methods.

I also added 4 test cases (3 from the original issue, one that I added during debugging).

- Since these instructions are gated behind the fr_logic calls, we can
  let the argument conversion in create_call handle their conversion
Copy link

@tim-hoffman tim-hoffman left a comment

Choose a reason for hiding this comment

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

Thanks! Looks great.

@iangneal iangneal merged commit 8f93b2e into llvm Aug 18, 2023
2 checks passed
@tim-hoffman tim-hoffman deleted the iangneal/VAN-503 branch August 21, 2023 14:54
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