Hi folks,Unsurprisingly, leveraging the fact that certain address spaces don't alias can significantly improve alias analysis precision and enhance (observably 2x performance gain) load/store optimizations such as LICM and DSE.This sounds to me an overdue feature. I saw several discussion threads on that direction, but none of them really happened.(1) http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20111010/129615.html. Justin Holewinski proposed to add an address-space alias analysis that treats pointers in different address spaces not aliasing. This patch got shot down because, in some targets, address spaces may alias. For example, in CUDA+NVPTX, addrspace(0) aliases everyone.(2) http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-August/064620.html. Michele Scandale proposed address space extensions in IR metadata which TBAA could then leverage to prove non-aliasing. This approach didn't fly either because address spaces are target-specific. The front end doesn't know enough to decide aliasing.
So, can we make BasicAA to consider address spaces? Specifically, I am proposing:a) adding a new interface like TTI::addressSpacesAlias(unsigned, unsigned), andb) adding a little piece of logic in BasicAA that reports "no alias" if address spaces don't alias.This approach addresses the issue brought up in (2) because TTI can see the entire codegen. It also resolves the issue that shut down (1) because it allows address spaces to alias in a target-defined way. Actually, John Criswell did mention in that thread the idea of embedding alias info in TargetData. Now that we have TTI, it seems a better place to hold target-specific alias info than DataLayout.Any comments?Jingyue
_______________________________________________ LLVM Developers mailing list llvm...@lists.llvm.org http://llvm.cs.uiuc.edu http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Not shocking
>>
>> This sounds to me an overdue feature. I saw several discussion threads on
>> that direction, but none of them really happened.
>>
>> (1)
>> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20111010/129615.html.
>> Justin Holewinski proposed to add an address-space alias analysis that
>> treats pointers in different address spaces not aliasing. This patch got
>> shot down because, in some targets, address spaces may alias. For example,
>> in CUDA+NVPTX, addrspace(0) aliases everyone.
ITYM other addrspace may alias addrspace(0).
Sorry to be pedantic, but i think it's important to make sure we are
all on the same page that backends can't change the aliasing behavior
of the default address space, only the aliasing behavior of the other
address spaces.
>>
>> So, can we make BasicAA to consider address spaces? Specifically, I am
>> proposing:
>> a) adding a new interface like TTI::addressSpacesAlias(unsigned,
>> unsigned), and
>> b) adding a little piece of logic in BasicAA that reports "no alias" if
>> address spaces don't alias.
>>
>> This approach addresses the issue brought up in (2) because TTI can see
>> the entire codegen. It also resolves the issue that shut down (1) because it
>> allows address spaces to alias in a target-defined way. Actually, John
>> Criswell did mention in that thread the idea of embedding alias info in
>> TargetData. Now that we have TTI, it seems a better place to hold
>> target-specific alias info than DataLayout.
>>
>> Any comments?
First, I agree this is a really useful feature to have.
If it really is target specific (and it seems to be), ISTM like TTI is
the right place to add a hook.
However, i'd still rather see it as a pass (as it was in 2011) and
something exposing the AA interface, than further push things into
basicaa.
It's not at all clear to me why basicaa should have this knowledge.
But this is a mild preference, if others think this is a bad idea, ...
-Matt
No.
I'm saying "your target can't directly change what address space 0's
aliasing properties are".
So if you wanted to say "on NVPTX, address space 0 aliases *everything
in the world, including everything in address space 0*", that is not
okay.
If they want to say "on NVPTX, all non-default address spaces alias
everything in address space 0", that is fine.
(Note: This does end up changing what alias queries return for
pointers in different address spaces, but it has no effect on two
pointers solely in address space 0)
In practice, because you can change the properties *of the other
address spaces*, and mayAlias is a symmetric relationship, it doesn't
matter for this.
But he wrote " For example,
>> in CUDA+NVPTX, addrspace(0) aliases everyone."
This is pedantically wrong. CUDA+NVPTX cannot and does not change the
behavior of aliasing in address space 0, it changes the behavior of
aliasing in all the other address spaces so that they alias pointers
in address space 0 :P.
(As i said, it's really pedantic, but we need to be absolutely clear
that targets do not control the properties of address space 0)
address space 0 so in some cases the frontend knows more about aliasing address spaces than the target.
-Matt
-Hal
address space 0 so in some cases the frontend knows more about aliasing address spaces than the target.
-Matt
--
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory
So the target would not be able to state that a pointer to global memory does not alias a pointer to local memory. But in the source language, you do have that information.
clang performs the mapping from source address space to target address
space. See AddrSpaceMap in clang's TargetInfo
But then that's too late for any address-space-based metadata. What you need is just aliasing metadata, which is another matter (and, to some extent, we already have).
-Hal
>
--
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory
For example (in our model), we have some constraints like this:
Global memory can’t alias local memory.
Global writeable memory can’t alias global readonly memory (different address spaces).
Stack memory can’t alias global memory (different address spaces).
Texture reads cannot alias texture writes, because you can’t bind a texture as readable and writeable at the same time. Texture writes, however, can alias each other.
Vertex shader outputs can’t really alias each other, even though they are technically “stores”.
(there’s more where that came from)
These are all very trivial to express in code (the trivially disjoint function in our backend is like 50 lines of code to cover all the cases), but a few of them are slightly more complex than “address space A can’t alias B”, so having a generic callback might be nicer and more powerful than a “does address space A alias address space B” callback, I think.
—escha
Could you provide a specific example of a case where the address space is not enough? [maybe you did above, but if so, I don't know which one].
Perhaps we should just do the most generic thing: Provide an AA/TTI shim which allows any target provide an implementation of AA (as part of the chain of AA passes). Thoughts?
-Hal
>
> —escha
--
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory
+1
-Hal
Actually, upon further reflection, I don't we should create a new AA interface for this unless that's really necessary. AA passes can currently provide alias, pointsToConstantMemory, getArgModRefInfo, etc. and the target can quite reasonably want to enhance many of these.
Unless there's some reason why we can't, I think we should provide the target the ability to provide an AA analysis pass to be inserted in the chain, or maybe TTI should just *be* an AA pass that gets inserted into the chain?
-Hal
I agree also, in general, this belongs in an AA pass and not the
interface (IE i don't think basicaa needs it).
However, for things like "memory spaces being disjoint", some other AA
passes may want to be able to know that.
IE If CFL-AA can tell that memory spaces are disjoint, it could avoid
unioning in stuff that can't really alias. Without such a hook, it
would be relegated to calling something like alias() on every pair :P
So i'm torn on how best to make that happen, without people going off
and completely making things like basicaa super target-specific using
hooks (such that it ends up providing pretty crappy answers unless you
implement 60 different target hooks)
----- Original Message -----
> From: "Jingyue Wu" <jin...@google.com>
> To: "Hal Finkel" <hfi...@anl.gov>
> Cc: llvm...@lists.llvm.org, "Justin Holewinski" <jhole...@nvidia.com>
> Sent: Wednesday, August 12, 2015 3:39:52 PM
> Subject: Re: [llvm-dev] [RFC] BasicAA considers address spaces?
>
> Then, we need to run this target-provided AA under -O3 to benefit the
> optimizations in O3.
>
> I'm not sure what's the best practice of doing this. One way is pass
> 1) add a new interface TTI.getTargetAwareAliasAnalysis that returns
> the target-provided AA or nullptr
> 2) Embed TTI in PassManagerBuilder
> 3) When PassManagerBuilder::addInitialAliasAnalysisPass adds
> TTI.getTargetAwareAliasAnalysis to the pipeline.
>
> Any better ideas?
I've cc'd Chandler so he can comment here.
Currently, TargetMachine can optionally return a TargetIRAnalysis object; this is then provided a function for which it can produce the actual TargetTransformInfo-derived object. TargetTransformInfoWrapperPass is the actual pass, and it just holds a pointer to the TargetIRAnalysis object.
In our case, we'd like to provide the target a way to add some AA pass to take advantage of target-specific knowledge regarding address spaces, intrinsics, and other IR constructs whose meaning is completely target specific. I'm not sure how well it fits into this model.
In addition, we have other use cases where targets want to add passes to handle target-specific things into the pipeline (http://reviews.llvm.org/D11782, for example, for doing target-specific loop-idiom recognition).
Plus, we already have a mechanism for allowing extension of the optimization pipeline, and I think the best way of approaching this (which is also useful for other use cases), is to provide the targets the ability to use this mechanism. I understand that this could be ripe for abuse (so we'd need to be vigilant in watching the targets), but nevertheless, how about this:
1. Add a function to TargetMachine called, for example, registerPassManagerBuilderExtensions(PassManagerBuilder *PMB). This would need to be called, for example, by the code in EmitAssemblyHelper in Clang in tools/clang/lib/CodeGen/BackendUtil.cpp (just as it currently calls TM->getTargetIRAnalysis() and so that it can call createTargetTransformInfoWrapperPass) and also registers other extensions itself.
2. registerPassManagerExtensions's job will be to call PassManagerBuilder::addExtension (or addGlobalExtension) as appropriate.
3. Create a new extension point for AA passes, and call addExtensionsToPM inside PassManagerBuilder::addInitialAliasAnalysisPasses
This will automatically cover a wide variety of use cases, including this one. Thoughts?
-Hal
>
>
We might be able to consider address spaces somewhat special in this regard -- they're already somewhat special. Like target-specific intrinsics, they are an IR-level feature with target-defined semantics. As a result, I feel it would be justified to add some additional IR-level support to provide some more information to the generic IR analysis. We could, for example, use module-level metadata to encode address-space disjointness information, and that could be leveraged by BasicAA, etc.
This fits with the role of metadata, in that if the metadata were dropped, the IR analysis would simply fallback to making the same kinds of conservative decisions it makes now.