Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IR] Support DiffRange multiplication #2310

Merged
merged 1 commit into from
May 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions taichi/analysis/value_diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ DiffRange operator-(const DiffRange &a, const DiffRange &b) {
a.low - b.high + 1, a.high - b.low);
}

DiffRange operator*(const DiffRange &a, const DiffRange &b) {
return DiffRange(
a.related_() && b.related_() && a.coeff * b.coeff == 0,
fmax(a.low * b.coeff, a.coeff * b.low),
fmin(a.low * b.low,
fmin(a.low * (b.high - 1),
fmin(b.low * (a.high - 1), (a.high - 1) * (b.high - 1)))),
fmax(a.low * b.low,
fmax(a.low * (b.high - 1),
fmax(b.low * (a.high - 1), (a.high - 1) * (b.high - 1)))) +
1);
}

namespace {

class ValueDiffLoopIndex : public IRVisitor {
Expand Down Expand Up @@ -87,16 +100,19 @@ class ValueDiffLoopIndex : public IRVisitor {

void visit(BinaryOpStmt *stmt) override {
if (stmt->op_type == BinaryOpType::add ||
stmt->op_type == BinaryOpType::sub) {
stmt->op_type == BinaryOpType::sub ||
stmt->op_type == BinaryOpType::mul) {
stmt->lhs->accept(this);
stmt->rhs->accept(this);
auto ret1 = results[stmt->lhs->instance_id];
auto ret2 = results[stmt->rhs->instance_id];
if (ret1.related_() && ret2.related_()) {
if (stmt->op_type == BinaryOpType::add) {
results[stmt->instance_id] = ret1 + ret2;
} else {
} else if (stmt->op_type == BinaryOpType::sub) {
results[stmt->instance_id] = ret1 - ret2;
} else {
results[stmt->instance_id] = ret1 * ret2;
}
return;
}
Expand Down