[LLVMdev] Optimization hints for "constant" loads

Kevin Modzelewski kmod at dropbox.com
Thu Sep 11 02:28:56 PDT 2014


On Wed, Sep 10, 2014 at 3:21 PM, Philip Reames <listmail at philipreames.com>
wrote:

>  On 09/10/2014 02:42 PM, Kevin Modzelewski wrote:
>
> We have some similar cases and wanted the same thing; what we were doing
> for a while is using the third "is constant" field of the TBAA metadata and
> setting that to 1.  I'm not 100% sure what the semantics of that are --
> LangRef says it means that pointsToConstantMemory() returns true which
> means that the memory is "impossible ... to be modified", which seems like
> not quite a fit for this set-exactly-once use case.  In practice, looking
> at the IR after our optimization pipeline, we were getting the results we
> wanted: if a store and subsequent loads were seen together, the store would
> remain and the value would be forwarded to all the loads.  (I don't think I
> looked at the "multiple loads with no visible store which should get
> collapsed to a single load" case.)  ymmv
>
> I hadn't looked at this approach much, but based on the documentation,
> you're basically just asking for miscompiles here.  The semantics seem to
> be the same as "invariant.load".   While the optimizer happens to not be
> removing the stores, it seems like it would be perfectly legal for it to do
> so.
>

Yeah, agreed that it's risky based on the documentation, but it feels like
this is the intended use case for that "is constant" TBAA field, since I'm
not sure when the described semantics could be useful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140911/cd81983e/attachment.html>


More information about the llvm-dev mailing list