[llvm-commits] [llvm] r89398 - in /llvm/trunk: include/llvm/Analysis/CaptureTracking.h lib/Analysis/BasicAliasAnalysis.cpp lib/Analysis/CaptureTracking.cpp lib/Transforms/IPO/FunctionAttrs.cpp test/Transforms/GVN/nonescaping-malloc.ll
Dan Gohman
gohman at apple.com
Fri Nov 20 11:32:51 PST 2009
On Nov 19, 2009, at 11:15 PM, Nick Lewycky wrote:
> Dan Gohman wrote:
>> Author: djg
>> Date: Thu Nov 19 15:57:48 2009
>> New Revision: 89398
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=89398&view=rev
>> Log:
>> Extend CaptureTracking to indicate when a value is never stored, even
>> if it is not ultimately captured. Teach BasicAliasAnalysis that a
>> local object address which does not escape and is never stored does
>> not alias with a value resulting from a load.
>>
>> Added:
>> llvm/trunk/test/Transforms/GVN/nonescaping-malloc.ll
>> Modified:
>> llvm/trunk/include/llvm/Analysis/CaptureTracking.h
>> llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
>> llvm/trunk/lib/Analysis/CaptureTracking.cpp
>> llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
>>
>> Modified: llvm/trunk/include/llvm/Analysis/CaptureTracking.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CaptureTracking.h?rev=89398&r1=89397&r2=89398&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Analysis/CaptureTracking.h (original)
>> +++ llvm/trunk/include/llvm/Analysis/CaptureTracking.h Thu Nov 19 15:57:48 2009
>> @@ -21,8 +21,12 @@
>> /// by the enclosing function (which is required to exist). This routine can
>> /// be expensive, so consider caching the results. The boolean ReturnCaptures
>> /// specifies whether returning the value (or part of it) from the function
>> + /// counts as capturing it or not. The boolean StoreCaptures specified whether
>> + /// storing the value (or part of it) into memory anywhere automatically
>> /// counts as capturing it or not.
>> - bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures);
>> + bool PointerMayBeCaptured(const Value *V,
>> + bool ReturnCaptures,
>> + bool StoreCaptures);
>
> I completely do not understand this. The fact that store implies capture has always been a missed opportunity; if it stores to something that never escapes, and the loads of it never escape, then it's not captured. (Note that you need to track 'pointer depth' as %p is stored into %q is stored into %r, etc.)
>
> Duncan (IIRC) actually implemented this behaviour early on and we removed it because it was likely to be slow and didn't seem to provide any performance benefit at the time.
>
> In any event, either I'm misunderstanding what you're doing here, or it doesn't belong in the API.
I didn't put any logic in PointerMayBeCaptured to implement
the !StoreCaptures case, so currently the flag doesn't do
anything. But, I did put code in BasicAA which benefits from
being able to assume that a locally allocated object address
which never escapes is never in memory, and thus is never
the result of a load. I added the flag to PointerMayBeCaptured
in order to allow BasicAA to make its assumption explicit.
For an example of what I was thinking about, see the testcase:
test/Transforms/GVN/nonescaping-malloc.ll
Dan
More information about the llvm-commits
mailing list