[PATCH] D47854: [LangRef] Clarify semantics of load metadata.

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 11 06:32:20 PDT 2018


hfinkel added inline comments.


================
Comment at: docs/LangRef.rst:7941
+program where the memory location is known to be dereferenceable;
+otherwise, the behavior is undefined.
 
----------------
nlopes wrote:
> hfinkel wrote:
> > nlopes wrote:
> > > aqjune wrote:
> > > > Hello, I have a minor question - is undefined behavior raised at the point when the load is executed? I wonder whether load with !invariant.load can be hoisted out of a loop (as in Nuno's example), even if the loaded value is actually not invariant.
> > > The way the sentence is written implies that !invariant.load needs to be stripped on hoisting. I grepped around and I saw very few cases where it is used. But I guess we cannot change the semantics to be "it has the same value always" since that would mean that memory region is constant instead, and that's not what we want.
> > > So, I guess UB is fine, but we need to strip it on hoisting.
> > > But I guess we cannot change the semantics to be "it has the same value always" since that would mean that memory region is constant instead, and that's not what we want.
> > 
> > Are you sure? I'm under the impression that this is used to indicate things like loads from constant memories on GPUs. I think that we should support hoisting without stripping for this. Granted, however, it means that there can't be any control dependencies on the validity of the metadata. If we have both kinds of use cases, then we'll need to introduce some way to distinguish them.
> > 
> The uses in clang:
> lib/CodeGen/CGObjC.cpp:        CGM.getModule().getMDKindID("invariant.load"),
> lib/CodeGen/CGObjCMac.cpp:    // Annotate the load as an invariant load iff inside an instance method
> lib/CodeGen/CGObjCMac.cpp:        ->setMetadata(CGM.getModule().getMDKindID("invariant.load"),
> lib/CodeGen/CGObjCMac.cpp:  LI->setMetadata(CGM.getModule().getMDKindID("invariant.load"),
> lib/CodeGen/ItaniumCXXABI.cpp:    // Add !invariant.load md to virtual function load to indicate that
> lib/CodeGen/ItaniumCXXABI.cpp:          llvm::LLVMContext::MD_invariant_load,
> 
> So there's definitely more than GPUs :)   (I didn't investigate these)
> 
> The way it's written right now says that the memory is only constant after the load is executed, but makes no promises before the load is executed. Which makes sense: if the instruction is never executed, how could it constrain the execution?
I don't know much about the Objective C bits, but for the vtbl loads, those are in constant memory. No?

> The way it's written right now says that the memory is only constant after the load is executed, but makes no promises before the load is executed. Which makes sense: if the instruction is never executed, how could it constrain the execution?

I think that, for loads that we know are into constant memory, we actually to have the guarantee. It means that, by the very act of forming the pointer that might potentially feed the load, we know that the pointer is to constant memory.


Repository:
  rL LLVM

https://reviews.llvm.org/D47854





More information about the llvm-commits mailing list