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] Dive into container statements to find local loads/stores for optimization, and optimize loads of new allocas to 0 #662
Conversation
I don't see a trivial way to check the statements for each kind of container statement. Shall we add a function like |
This can be a very useful |
(Maybe I reviewed too early - feel free to re-request my review when you need next time.) |
I found The number of statements of |
AWESOME!! |
Diving into container statements does nothing to
to
further reduces the number of statements to 58. |
Cool! At some point in the future, you may want to expand your test set and write an automatic tool to summarize how many instructions are generated in each test case :-) |
taichi/transforms/simplify.cpp
Outdated
#include "taichi/ir/ir.h" | ||
|
||
TLANG_NAMESPACE_BEGIN | ||
|
||
// Find if there is a load following a store in a basic block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that LocalLoadSearcher
is just finding loads, since LocalStore
is not mentioned here. I'm confused...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, LocalLoadSearcher
is finding loads all over the root
, with root
actually be a statement after LocalStore
, passed in as an argument. I'd better change the comment to simply Find if there is a load
.
taichi/transforms/simplify.cpp
Outdated
} | ||
}; | ||
|
||
// Find if there is a store preceding a load in a basic block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, isn't this simply Find if there is a store
?
taichi/transforms/simplify.cpp
Outdated
} | ||
}; | ||
|
||
// Find the **last** store preceding a load in a basic block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, how does this ensure preceding
?
Oh no I'm breaking tests. Go debugging. |
I see what the bug is: sometimes I find a store that is not the last one in
to (replace all usages of $31 with $30)? Or does |
Yes, |
I see. So if the last statement is an |
Should be working now. The good news is number 58 here doesn't change.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
…ptimization, and optimize loads of new allocas to 0 (taichi-dev#662) * refactor BasicBlockSimplify::visit(LocalStoreStmt*) * refactor again, making use of visitors * [skip ci] same for visit(LocalLoadStmt *) * [skip ci] LocalStoreForwarder * Optimize loads of new allocas to const[0] * [skip ci] enforce code format * Add assertions and update comments * fixed LocalStoreForwarder * [skip ci] enforce code format * [skip ci] minor: update comment * [skip ci] minor: update comment * Update simplify.cpp Co-authored-by: Taichi Gardener <taichigardener@gmail.com> Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>
Related issue = #656
[Click here for the format server]