Repository navigation
Add .lower() methods to reduction and replication expressions - #9123
Merged
Merged
Conversation
kroening
requested review from
TGWDB,
martin-cs,
peterschrammel and
tautschnig
as code owners
July 21, 2026 11:30
kroening
force-pushed
the
kroening/bitvector-expr-lower-methods
branch
4 times, most recently
from
July 21, 2026 12:22
3961543 to
67842c6
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9123 +/- ##
===========================================
+ Coverage 80.84% 80.85% +0.01%
===========================================
Files 1717 1717
Lines 190084 190153 +69
Branches 73 73
===========================================
+ Hits 153664 153751 +87
+ Misses 36420 36402 -18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tautschnig
reviewed
Sep 22, 2026
Comment on lines
+392
to
+400
| exprt replication_exprt::lower() const | ||
| { | ||
| auto count = numeric_cast_v<std::size_t>(times()); | ||
| exprt::operandst ops; | ||
| ops.reserve(count); | ||
| for(std::size_t i = 0; i < count; i++) | ||
| ops.push_back(op()); | ||
| return concatenation_exprt{std::move(ops), type()}; | ||
| } |
Collaborator
There was a problem hiding this comment.
I believe we want PRECONDITION(count >= 1).
Collaborator
Author
There was a problem hiding this comment.
Verilog does allow zero replications in concatenations; I realise this makes lowering to SMT-LIB a bit harder. I'll add a comment.
Collaborator
There was a problem hiding this comment.
We might just need to fix it on the SMT-LIB output side (which already tries to catch zero-width expressions in some places).
kroening
force-pushed
the
kroening/bitvector-expr-lower-methods
branch
2 times, most recently
from
September 23, 2026 20:17
7c32259 to
7e9f532
Compare
Add lower() methods to reduction_and_exprt, reduction_nand_exprt, reduction_or_exprt, reduction_nor_exprt, reduction_xor_exprt, reduction_xnor_exprt, and replication_exprt in bitvector_expr.h/cpp. These methods lower high-level bitvector reduction and replication operators to simpler expression forms: - reduction_and(a) → (a = all_ones) - reduction_nand(a) → (a != all_ones) - reduction_or(a) → (a != 0) - reduction_nor(a) → (a = 0) - reduction_xor(a) → a[0] ^ a[1] ^ ... ^ a[n-1] - reduction_xnor(a) → !(a[0] ^ a[1] ^ ... ^ a[n-1]) - replication(n, x) → x :: x :: ... :: x (n times) Use the new .lower() methods in smt2_conv.cpp to replace inline lowering code for reduction_and, reduction_nand, reduction_or, reduction_nor, and reduction_xnor. The reduction_xor case retains its native SMT-LIB encoding using extract + bvxor for efficiency. Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
kroening
force-pushed
the
kroening/bitvector-expr-lower-methods
branch
from
September 23, 2026 20:21
7e9f532 to
82e0fce
Compare
tautschnig
approved these changes
Sep 23, 2026
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.
Add
lower()methods toreduction_and_exprt,reduction_nand_exprt,reduction_or_exprt,reduction_nor_exprt,reduction_xor_exprt,reduction_xnor_exprt, andreplication_exprtinbitvector_expr.h/bitvector_expr.cpp.These methods lower high-level bitvector reduction and replication operators to simpler expression forms:
reduction_and(a)→(a = all_ones)reduction_nand(a)→(a != all_ones)reduction_or(a)→(a != 0)reduction_nor(a)→(a = 0)reduction_xor(a)→a[0] ^ a[1] ^ ... ^ a[n-1]reduction_xnor(a)→!(a[0] ^ a[1] ^ ... ^ a[n-1])replication(n, x)→x :: x :: ... :: x(n times)Use the new
.lower()methods insmt2_conv.cppto replace inline lowering code forreduction_and,reduction_nand,reduction_or,reduction_nor, andreduction_xnor. Thereduction_xorcase retains its native SMT-LIB encoding usingextract+bvxorfor efficiency.The boolbv layer is not changed since it operates at the propositional literal level, and the SMT2 replication keeps its native
repeatoperator.Companion to diffblue/hw-cbmc#2037 which will use these methods via
.lower()instead of free functions.