[BV] Fix order of rewrites for `concat` (#8010)
authorAndres Noetzli <andres.noetzli@gmail.com>
Tue, 1 Feb 2022 20:27:56 +0000 (12:27 -0800)
committerGitHub <noreply@github.com>
Tue, 1 Feb 2022 20:27:56 +0000 (20:27 +0000)
This commit fixes the order of the rewrites for bit-vector
concatentation such that the rewrite that merges adjacents constants
comes last (the commit also updates the comments to be less confusing).
Before, it could happen that the rewrite step that removes unnecessary
extract operations introduces constants then then would not get merged
before returning REWRITE_DONE.

src/theory/bv/theory_bv_rewriter.cpp

index 97ca24437851d003be810eb81073ddbc2c2f08e4..4bfddf1a7f97e46b0dd43a3d19de6849037002fb 100644 (file)
@@ -279,13 +279,14 @@ RewriteResponse TheoryBVRewriter::RewriteExtract(TNode node, bool prerewrite) {
 RewriteResponse TheoryBVRewriter::RewriteConcat(TNode node, bool prerewrite)
 {
   Node resultNode = LinearRewriteStrategy<
-      RewriteRule<ConcatFlatten>,
       // Flatten the top level concatenations
-      RewriteRule<ConcatExtractMerge>,
+      RewriteRule<ConcatFlatten>,
       // Merge the adjacent extracts on non-constants
-      RewriteRule<ConcatConstantMerge>,
+      RewriteRule<ConcatExtractMerge>,
+      // Remove extracts that have no effect
+      ApplyRuleToChildren<kind::BITVECTOR_CONCAT, ExtractWhole>,
       // Merge the adjacent extracts on constants
-      ApplyRuleToChildren<kind::BITVECTOR_CONCAT, ExtractWhole>>::apply(node);
+      RewriteRule<ConcatConstantMerge>>::apply(node);
   return RewriteResponse(REWRITE_DONE, resultNode);
 }