[RFC] allow noundef metadata only on loads

Problem

Currently there is no restrictions on where it is possible to add !noundef metadata and as there also is the noundef return attribute this result in booth attribute and metadata possibly is set on call/invoke and need to be handled.

Solution

Like for e.g. nonnull let the verifier reject !noundef metadata unless it is on a load instruction.
call/invoke instructions will then need to use the noundef return attribute instead of the metadata.

1 Like

This makes sense to me as a general direction.

Do we need !noundef on other native instructions? How do atomicrmw and cmpxchg interact with undef?

Last time I looked at this I concluded that they were forgotten about. They probably should be supported though

I suggested only loads as that was the only usage except calls that I found when I searched for LLVMContext::MD_noundef.

Restricting !noundef metadata to loads in the verifier makes sense to me. We already only document !noundef support for loads in LangRef, and our core isGuaranteedNotToBeUndefOrPoison() analysis only handles it on loads. So the metadata is already load-only, both de jure and de facto – we just fail to verify it.

As for atomicrmw, I do agree that all the load value metadata could in principle also be applied to atomicrmw, but that seems like a largely unrelated extension, that should be done for all the load metadata at the same time.