[llvm] [Loads] Check loop-varying pointer in isDereferenceableAndAlignedInLoop. (PR #120962)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 09:12:36 PST 2025


nikic wrote:

> > For dereferenceable on arguments, our current de-facto semantics are that the pointer must stay dereferenceable until the end of the function.
> 
> That is not true, at least not what we "agreed on" a long time ago. IIRC: Deref means deref at the spot (I mentioned it as part of this builtin as well: [#120755 (comment)](https://github.com/llvm/llvm-project/pull/120755#issuecomment-2573776216)). I think we introduced `nofree` for this reason, basically arguments with deref + nofree => deref to the return. We also discussed deref of globals and other constructs in length, which are deref globally. I don't have the discussion thread but I immediately found what we never implemented: https://reviews.llvm.org/D61652

That's why I said de-facto semantics :) In our current implementation the dereferenceable attribute applies for the whole function. Aspirationally, we'd like to use deref-at-point semantics, but we currently don't.

We have a flag UseDerefAtPointSemantics to enable those, but the implementation never got to a usable point. Part of the reason is that we never got a consensus on some key semantics questions, in particular relating to the interaction of noalias, nofree and nosync.

But in any case, I think that for dereferenceable *assumptions* we do need to use deref-at-point semantics, otherwise it's too easy for things to go wrong.

https://github.com/llvm/llvm-project/pull/120962


More information about the llvm-commits mailing list