Skip to content

Commit

Permalink
[fix] rewriting ordering for terms with equal height
Browse files Browse the repository at this point in the history
  • Loading branch information
Columpio committed Oct 24, 2023
1 parent 176620e commit 3678f91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions include/klee/Expr/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ class Expr {
std::string toString() const;

/// Returns the pre-computed hash of the current expression
virtual unsigned hash() const { return hashValue; }
virtual unsigned height() const { return heightValue; }
unsigned hash() const { return hashValue; }
unsigned height() const { return heightValue; }

/// (Re)computes the hash of the current expression.
/// Returns the hash value.
Expand Down
32 changes: 14 additions & 18 deletions lib/Expr/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,27 +423,23 @@ Simplificator::simplifyExpr(const constraints_ty &constraints,

for (auto &constraint : constraints) {
if (const EqExpr *ee = dyn_cast<EqExpr>(constraint)) {
ref<Expr> left = ee->left;
ref<Expr> right = ee->right;
if (right->height() < left->height()) {
left = ee->right;
right = ee->left;
}
if (isa<ConstantExpr>(ee->left)) {
equalities.insert(std::make_pair(ee->right, ee->left));
equalitiesParents.insert({ee->right, constraint});
} else {
equalities.insert(std::make_pair(constraint, Expr::createTrue()));
equalities.insert(std::make_pair(right, left));
equalitiesParents.insert({constraint, constraint});
equalitiesParents.insert({right, constraint});
ref<Expr> small = ee->left;
ref<Expr> big = ee->right;
if (!isa<ConstantExpr>(small)) {
auto hr = big->height(), hl = small->height();
if (hr < hl || (hr == hl && big < small))
std::swap(small, big);
equalities.emplace(constraint, Expr::createTrue());
equalitiesParents.emplace(constraint, constraint);
}
equalities.emplace(big, small);
equalitiesParents.emplace(big, constraint);
} else {
equalities.insert(std::make_pair(constraint, Expr::createTrue()));
equalitiesParents.insert({constraint, constraint});
equalities.emplace(constraint, Expr::createTrue());
equalitiesParents.emplace(constraint, constraint);
if (const NotExpr *ne = dyn_cast<NotExpr>(constraint)) {
equalities.insert(std::make_pair(ne->expr, Expr::createFalse()));
equalitiesParents.insert({ne->expr, constraint});
equalities.emplace(ne->expr, Expr::createFalse());
equalitiesParents.emplace(ne->expr, constraint);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions lib/Expr/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ int Expr::compare(const Expr &b, ExprEquivSet &equivs) const {
return 0;

Kind ak = getKind(), bk = b.getKind();
if (ak != bk)
return (ak < bk) ? -1 : 1;
int kc = (ak > bk) - (ak < bk);
if (kc)
return kc;

if (hashValue != b.hashValue)
return (hashValue < b.hashValue) ? -1 : 1;
int hc = (hashValue > b.hashValue) - (hashValue < b.hashValue);
if (hc)
return hc;

if (int res = compareContents(b))
return res;
Expand Down

0 comments on commit 3678f91

Please sign in to comment.