add interval analysis option for constant folding
@@ -47,6 +47,7 @@ pub fn letter(i: usize) -> &'static str {
pub enum ConstantFoldMethod {
NoFold, // disables constant folding
CvecMatching, // constant folding done by cvec matching
+ IntervalAnalysis, // constant folding done by interval analysis
Lang, // constant folding implemented by language
}
@@ -1471,6 +1472,22 @@ impl<L: SynthLanguage> egg::Analysis<L> for SynthAnalysis {
}
}
}
+ ConstantFoldMethod::IntervalAnalysis => {
+ let interval = &egraph[id].data.interval;
+ match interval {
+ Interval {
+ low: Some(a),
+ high: Some(b),
+ } => {
+ if a == b {
+ let enode = L::mk_constant(a.clone());
+ let added = egraph.add(enode);
+ egraph.union(id, added);
+ }
+ }
+ _ => {}
+ };
+ }
ConstantFoldMethod::Lang => {
if egraph[id].data.exact {
L::constant_fold(egraph, id);
