Skip to content

Simplify all-zero or all-one constants in bitand/bitor#8944

Merged
kroening merged 1 commit intodiffblue:developfrom
tautschnig:simplify/bitand-bitor-constants
Apr 9, 2026
Merged

Simplify all-zero or all-one constants in bitand/bitor#8944
kroening merged 1 commit intodiffblue:developfrom
tautschnig:simplify/bitand-bitor-constants

Conversation

@tautschnig
Copy link
Copy Markdown
Collaborator

all-zeros in bitand yields zero, all-ones in bitor yield all-ones.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Apr 1, 2026
Copilot AI review requested due to automatic review settings April 1, 2026 16:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds simplification rules for bitwise operations involving all-zero/all-one constants, plus new regression tests around expression simplification.

Changes:

  • Simplify bitand to zero when any operand is an all-zero bitvector constant.
  • Simplify bitor to all-ones when any operand is an all-ones constant.
  • Add unit tests for bitand/all-zero and a few other simplify rules.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/util/simplify_expr_int.cpp Implements early-return simplifications for bitand with all-zeros and bitor with all-ones.
unit/util/simplify_expr.cpp Adds new simplification regression tests, including all-zero in bitand.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.48%. Comparing base (c740a89) to head (6e0af33).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8944      +/-   ##
===========================================
+ Coverage    80.47%   80.48%   +0.01%     
===========================================
  Files         1704     1704              
  Lines       188702   188749      +47     
  Branches        73       73              
===========================================
+ Hits        151854   151911      +57     
+ Misses       36848    36838      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kroening
Copy link
Copy Markdown
Collaborator

kroening commented Apr 3, 2026

We've got all_zeros_expr() and all_ones_expr(). In particular, from_integer will fail on bv_typet, which has no numerical interpretation.

@tautschnig tautschnig force-pushed the simplify/bitand-bitor-constants branch from f8073ad to 64f338e Compare April 3, 2026 10:07
@tautschnig
Copy link
Copy Markdown
Collaborator Author

We've got all_zeros_expr() and all_ones_expr(). In particular, from_integer will fail on bv_typet, which has no numerical interpretation.

Done and included an additional test for the possibly-failing case.

: from_integer(0, new_expr.type());
for(const auto &op : new_expr.operands())
{
if(op.is_constant() && op == zero)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You don't need the op.is_constant()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed (in both places).

@kroening kroening assigned tautschnig and unassigned kroening and peterschrammel Apr 8, 2026
all-zeros in bitand yields zero, all-ones in bitor yield all-ones.
Use from_integer() for type-agnostic constant construction so the
rules apply to all bitvector types (bv, unsignedbv, signedbv), not
just bv_typet.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig force-pushed the simplify/bitand-bitor-constants branch from 64f338e to 6e0af33 Compare April 9, 2026 11:05
@kroening kroening merged commit 582cc2a into diffblue:develop Apr 9, 2026
43 checks passed
@tautschnig tautschnig deleted the simplify/bitand-bitor-constants branch April 9, 2026 21:23
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.

4 participants