In case of non-alloca pointers, we check for whether it is a pointer
from malloc-like calls and it is not captured. In such case, we can
promote the pointer, as the caller will have no way to access this pointer
even if there is unwinding in middle of the loop.
Details
Diff Detail
- Build Status
Buildable 3020 Build 3020: arc lint + arc unit
Event Timeline
lib/Transforms/Scalar/LICM.cpp | ||
---|---|---|
1017–1018 | Is there an existing testcase which covers this? | |
1021 | Can we avoid calling PointerMayBeCaptured twice? (We perform a similar check later in this function.) | |
test/Transforms/LICM/scalar-promote-unwind.ll | ||
210 | It would be more useful to have a testcase which doesn't leak memory. |
Address comments.
- Call PointerMayBeCaptured only once.
- 2 test cases for malloced memory, first can escape and the other cant.
Make sure only the latter is promoted.
lib/Transforms/Scalar/LICM.cpp | ||
---|---|---|
1030 | I was thinking of something more like if (!isa<AllocaInst>()) { if (!isAllocLikeFn()) return false; [...] }. | |
test/Transforms/LICM/scalar-promote-unwind.ll | ||
248 | This doesn't really test what you want it to... it would fail the aliasing test anyway. Actually, hmm, it's hard to come up with a practical test where the PointerMayBeCaptured check is actually necessary: you need a call which could throw, but provably doesn't access a malloc whose address is captured... our current AA infrastructure can't prove something like that given the way C++ unwinding works. I guess you could construct an artificial IR testcase with a call that's readnone but not nothrow. |
test/Transforms/LICM/scalar-promote-unwind.ll | ||
---|---|---|
248 | yea, thats what i can think off right now. the problem is if the ptr escapes, then the function that actually throws will potentially be able to read/write it ... |
Is there an existing testcase which covers this?