Currently, memcpy callslot optimization doesn't happen if the memcpy's
destination starts its lifetime between the call and the memcpy. We can
make the optimization happen by extending the allocas lifetime to start
before the call, but we must only do that if the callslot optimization
succeeds, because otherwise we might lose some opportunities for stack
slot sharing
Details
- Reviewers
- None
Diff Detail
Event Timeline
I'm reasonable sure this code is correct, but I'm not sure it's as well structured as it could be. I reserve the right to be wrong here; you may just need to explain a few things. :)
lib/Transforms/Scalar/MemCpyOptimizer.cpp | ||
---|---|---|
891 | I'm a bit concerned about running these queries unconditionally. MDA is rather expensive. | |
894 | I'm not clear I understand the problem here. Is the issue that MD->getDependency is returning the lifetime_start as the dependency but MD->getPointerDependency(Src) is not? Also, would it be *correct* to always use the source pointer dependency here? Or do you need to consider both source and dest dependencies when considering the callSlotOpt? Depending on the implementation of the callSlotOpt, I could see that going either way. |
p.s. You may be interested in the bug I just filed on a related issue. http://llvm.org/bugs/show_bug.cgi?id=22758
lib/Transforms/Scalar/MemCpyOptimizer.cpp | ||
---|---|---|
894 | Yes, MD->getDependency returns the lifetime_start as the dependency. It would be incorrect to always use the source pointer dependency here, because we would then apply the call slot optimization to cases like this: memset(%src, 0, 1000) memset(%dst, 1, 1000) foo(dst) memcpy(%dst, %src, 1000) foo(dst) transforming it to memset(%dst, 0, 1000) memset(%dst, 1, 1000) foo(dst) foo(dst) Unfortunately the same is true for this patch when %dst has multiple lifetime ranges like this: memset(%src, 0, 1000) lifetime_start(1000, %dst) memset(%dst, 1, 1000) foo(dst) lifetime_end(1000, %dst) lifetime_start(1000, %dst) memcpy(%dst, %src, 1000) foo(dst) lifetime_end(1000, %dst) I'll have to rethink this. |
I'm a bit concerned about running these queries unconditionally. MDA is rather expensive.