Skip to content

Commit d74463a

Browse files
Columpiomisonijnik
authored andcommitted
[fix] rewriting ordering for terms with equal height
1 parent d8ff87b commit d74463a

3 files changed

Lines changed: 22 additions & 24 deletions

File tree

include/klee/Expr/Expr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ class Expr {
304304
std::string toString() const;
305305

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

310310
/// (Re)computes the hash of the current expression.
311311
/// Returns the hash value.

lib/Expr/Constraints.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -423,27 +423,23 @@ Simplificator::simplifyExpr(const constraints_ty &constraints,
423423

424424
for (auto &constraint : constraints) {
425425
if (const EqExpr *ee = dyn_cast<EqExpr>(constraint)) {
426-
ref<Expr> left = ee->left;
427-
ref<Expr> right = ee->right;
428-
if (right->height() < left->height()) {
429-
left = ee->right;
430-
right = ee->left;
431-
}
432-
if (isa<ConstantExpr>(ee->left)) {
433-
equalities.insert(std::make_pair(ee->right, ee->left));
434-
equalitiesParents.insert({ee->right, constraint});
435-
} else {
436-
equalities.insert(std::make_pair(constraint, Expr::createTrue()));
437-
equalities.insert(std::make_pair(right, left));
438-
equalitiesParents.insert({constraint, constraint});
439-
equalitiesParents.insert({right, constraint});
426+
ref<Expr> small = ee->left;
427+
ref<Expr> big = ee->right;
428+
if (!isa<ConstantExpr>(small)) {
429+
auto hr = big->height(), hl = small->height();
430+
if (hr < hl || (hr == hl && big < small))
431+
std::swap(small, big);
432+
equalities.emplace(constraint, Expr::createTrue());
433+
equalitiesParents.emplace(constraint, constraint);
440434
}
435+
equalities.emplace(big, small);
436+
equalitiesParents.emplace(big, constraint);
441437
} else {
442-
equalities.insert(std::make_pair(constraint, Expr::createTrue()));
443-
equalitiesParents.insert({constraint, constraint});
438+
equalities.emplace(constraint, Expr::createTrue());
439+
equalitiesParents.emplace(constraint, constraint);
444440
if (const NotExpr *ne = dyn_cast<NotExpr>(constraint)) {
445-
equalities.insert(std::make_pair(ne->expr, Expr::createFalse()));
446-
equalitiesParents.insert({ne->expr, constraint});
441+
equalities.emplace(ne->expr, Expr::createFalse());
442+
equalitiesParents.emplace(ne->expr, constraint);
447443
}
448444
}
449445
}

lib/Expr/Expr.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ int Expr::compare(const Expr &b, ExprEquivSet &equivs) const {
153153
return 0;
154154

155155
Kind ak = getKind(), bk = b.getKind();
156-
if (ak != bk)
157-
return (ak < bk) ? -1 : 1;
156+
int kc = (ak > bk) - (ak < bk);
157+
if (kc)
158+
return kc;
158159

159-
if (hashValue != b.hashValue)
160-
return (hashValue < b.hashValue) ? -1 : 1;
160+
int hc = (hashValue > b.hashValue) - (hashValue < b.hashValue);
161+
if (hc)
162+
return hc;
161163

162164
if (int res = compareContents(b))
163165
return res;

0 commit comments

Comments
 (0)