Skip to content

Commit

Permalink
[feat] Propagate equalities into a SelectExpr
Browse files Browse the repository at this point in the history
[feat] Split condition before to adding it to replacements
  • Loading branch information
misonijnik committed Jun 12, 2023
1 parent 1388aa6 commit d9e61ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/Expr/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,22 @@ class ExprReplaceVisitor2 : public ExprVisitor {
: Action::changeTo(visit(sexpr.falseExpr));
}

std::vector<ref<Expr>> splittedCond;
Expr::splitAnds(cond, splittedCond);

ExprHashMap<ref<Expr>> localReplacements;
if (const EqExpr *ee = dyn_cast<EqExpr>(cond)) {
if (isa<ConstantExpr>(ee->left)) {
localReplacements.insert(std::make_pair(ee->right, ee->left));
for (auto scond : splittedCond) {
if (const EqExpr *ee = dyn_cast<EqExpr>(scond)) {
if (isa<ConstantExpr>(ee->left)) {
localReplacements.insert(std::make_pair(ee->right, ee->left));
} else {
localReplacements.insert(
std::make_pair(scond, ConstantExpr::alloc(1, Expr::Bool)));
}
} else {
localReplacements.insert(
std::make_pair(cond, ConstantExpr::alloc(1, Expr::Bool)));
std::make_pair(scond, ConstantExpr::alloc(1, Expr::Bool)));
}
} else {
localReplacements.insert(
std::make_pair(cond, ConstantExpr::alloc(1, Expr::Bool)));
}

replacements.push_back(localReplacements);
Expand Down
10 changes: 10 additions & 0 deletions lib/Expr/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,16 @@ static ref<Expr> EqExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
return EqExpr::create(al->left, ar->left);
}
return EqExpr::alloc(l, r);
} else if (isa<SelectExpr>(l) || isa<SelectExpr>(r)) {
if (SelectExpr *se = dyn_cast<SelectExpr>(l)) {
return SelectExpr::create(se->cond, EqExpr::create(se->trueExpr, r),
EqExpr::create(se->falseExpr, r));
}
if (SelectExpr *se = dyn_cast<SelectExpr>(r)) {
return SelectExpr::create(se->cond, EqExpr::create(se->trueExpr, l),
EqExpr::create(se->falseExpr, l));
}
return EqExpr::alloc(l, r);
} else {
return EqExpr::alloc(l, r);
}
Expand Down

0 comments on commit d9e61ed

Please sign in to comment.