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

[opt] Enable CFG optimization for local tensors #3237

Merged
merged 5 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion taichi/analysis/alias_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ AliasResult alias_analysis(Stmt *var1, Stmt *var2) {
Stmt *origin1 = retrieve_local(var1);
Stmt *origin2 = retrieve_local(var2);
if (origin1 != nullptr && origin2 != nullptr) {
if (origin1 == origin2)
if (origin1 == origin2) {
if (var1->is<PtrOffsetStmt>() && var2->is<PtrOffsetStmt>()) {
auto diff = value_diff_ptr_index(var1->cast<PtrOffsetStmt>()->offset,
var2->cast<PtrOffsetStmt>()->offset);
if (diff.is_diff_certain) {
return diff.diff_range == 0 ? AliasResult::same
: AliasResult::different;
}
}
return AliasResult::uncertain;
}
if (origin1->is<AllocaStmt>() || origin2->is<AllocaStmt>())
return AliasResult::different;
TI_ASSERT(origin1->is<GlobalTemporaryStmt>() &&
Expand Down
2 changes: 1 addition & 1 deletion taichi/analysis/data_source_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::vector<Stmt *> get_load_pointers(Stmt *load_stmt) {

Stmt *get_store_data(Stmt *store_stmt) {
// If store_stmt provides one data source, return the data.
if (store_stmt->is<AllocaStmt>()) {
if (store_stmt->is<AllocaStmt>() && !store_stmt->ret_type->is<TensorType>()) {
// For convenience, return store_stmt instead of the const [0] it actually
// stores.
return store_stmt;
Expand Down
17 changes: 8 additions & 9 deletions taichi/ir/control_flow_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,10 @@ bool CFGNode::store_to_load_forwarding(bool after_lower_access) {
if (auto local_load = stmt->cast<LocalLoadStmt>()) {
bool regular = true;
auto alloca = local_load->src[0].var;
// TODO: store-to-load forwarding with TensorType Alloca
if (alloca->is<PtrOffsetStmt>()) {
regular = false;
} else {
for (int l = 0; l < stmt->width(); l++) {
if (local_load->src[l].offset != l ||
local_load->src[l].var != alloca) {
regular = false;
}
for (int l = 0; l < stmt->width(); l++) {
if (local_load->src[l].offset != l ||
local_load->src[l].var != alloca) {
regular = false;
}
}
if (regular) {
Expand Down Expand Up @@ -711,6 +706,10 @@ void ControlFlowGraph::live_variable_analysis(
if (stmt->is<AllocaStmt>() || stmt->is<AdStackAllocaStmt>()) {
return false;
}
if (stmt->is<PtrOffsetStmt>() &&
stmt->cast<PtrOffsetStmt>()->origin->is<AllocaStmt>()) {
return false;
}
if (auto *gptr = stmt->cast<GlobalPtrStmt>();
gptr && config_opt.has_value()) {
TI_ASSERT(gptr->snodes.size() == 1);
Expand Down