feat: NORM_BV_MUL_POW2_REV Bitvector rewrite#12455
feat: NORM_BV_MUL_POW2_REV Bitvector rewrite#12455bollu wants to merge 6 commits intoleanprover:masterfrom
Conversation
This shows up on some problems SMT-LIB/nötzli.
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
/--
info: BitVec.extractLsb'_append_zero_eq_mul_shiftLeft {n m : Nat} (x : BitVec n) (tz : Nat) (hm : n = m + tz) :
BitVec.extractLsb' 0 m x ++ 0#tz = BitVec.cast hm (x * 1#n <<< tz)
-/
#guard_msgs in #check BitVec.extractLsb'_append_zero_eq_mul_shiftLeft
/--
info: BitVec.shiftLeft_eq_concat_of_lt {w : Nat} {x : BitVec w} {n : Nat} (hn : n < w) :
x <<< n = BitVec.cast ⋯ (BitVec.extractLsb' 0 (w - n) x ++ 0#n)
-/
#guard_msgs in #check BitVec.shiftLeft_eq_concat_of_ltthe new rewrite |
// https://github.com/bitwuzla/bitwuzla/blob/main/src/rewrite/rewriter.cpp#L83C1-L84C1
d_arithmetic(level == LEVEL_ARITHMETIC),
...
//https://github.com/bitwuzla/bitwuzla/blob/main/src/rewrite/rewriter.cpp#L1251-L1254
if (d_arithmetic)
{
BZLA_APPLY_RW_RULE(NORM_BV_MUL_POW2_REV);
}
...
// https://github.com/bitwuzla/bitwuzla/blob/main/src/rewrite/rewriter.cpp#L1251-L1254
if (!d_arithmetic)
{
BZLA_APPLY_RW_RULE(BV_MUL_POW2);
}Bitwuzla has three sets of normalization rules: the default set that's always run, the arithmetic set, and the "anti-arithmetic" set which breaks arithmetic down into bitwise rewrites. The arithmetic level is not accessible from userspace: // https://github.com/bitwuzla/bitwuzla/blob/8f28c2e8d465576e91931787a9062f2a93d072f1/src/rewrite/rewriter.h#L60-L61
/**
* The level of speculative rewrites. This level can not be configured
* from the outside and rewrites of this level are only applied specifically
* for normalization.
*/
inline static constexpr uint8_t LEVEL_ARITHMETIC = LEVEL_MAX + 1;and is specially initialized by the // https://github.dev/bitwuzla/bitwuzla/blob/8f28c2e8d465576e91931787a9062f2a93d072f1/src/preprocess/pass/normalize.cpp#L248-L255
PassNormalize::PassNormalize(Env& env,
backtrack::BacktrackManager* backtrack_mgr)
: PreprocessingPass(env, backtrack_mgr, "no", "normalize"),
d_rewriter(env, Rewriter::LEVEL_ARITHMETIC, "normalize"),
d_stats(env.statistics(), "preprocess::" + name() + "::")
{
}I suggest that we mimic this, and maintain three different simproc sets, called |
This PR adds a rewrite rule
NORM_BV_MUL_POW2_REV,which we suspect will improve
bv_decide's performance onproblems from nötzli.