Skip to content

Commit

Permalink
egraph: improve merge-left-shift
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Dec 19, 2024
1 parent 8b6e916 commit 8596aad
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions patronus-egraphs/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ pub fn create_rewrites() -> Vec<ArithRewrite> {
// (a << b) << x <=> a << (b + c)
arith_rewrite!("merge-left-shift";
// we require that b, c and (b + c) are all unsigned
"(<< ?wo ?wab unsign (<< ?wab ?wa unsign ?a ?wb unsign ?b) ?wc unsign ?c)" =>
"(<< ?wo ?wa unsign ?a (max+1 ?wb ?wc) unsign (+ (max+1 ?wb ?wc) ?wb unsign ?b ?wc unsign ?c))";
// we do not want (b + c) to wrap, because in that case the result would always be zero
// wa == wb && wo >= wa && wab == wo
if["?wo", "?wa", "?wb", "?wab"], |w| w[1] == w[2] && w[0] >= w[1] && w[0] == w[3]),
"(<< ?wo ?wab unsign (<< ?wab ?wa ?sa ?a ?wb unsign ?b) ?wc unsign ?c)" =>
"(<< ?wo ?wa ?sa ?a (max+1 ?wb ?wc) unsign (+ (max+1 ?wb ?wc) ?wb unsign ?b ?wc unsign ?c))";
// wab >= wo
if["?wo", "?wab"], |w| w[1] >= w[0]),
// a * 2 <=> a + a
arith_rewrite!("mult-to-add";
"(* ?wo ?wa ?sa ?a ?wb ?sb 2)" =>
Expand Down

0 comments on commit 8596aad

Please sign in to comment.