[llvm] [LICM][SimplifyCFG] Ignore frees for writable dereferenceability check (PR #202589)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 01:01:19 PDT 2026
================
@@ -2149,9 +2149,13 @@ bool llvm::promoteLoopAccessesToScalars(
if (StoreSafety == StoreSafetyUnknown) {
Value *Object = getUnderlyingObject(SomePtr);
bool ExplicitlyDereferenceableOnly;
+ // The dereferenceability query here is only required to satisfy the
+ // writable contract, actual dereferenceability has already been proven
+ // above. As such, we can ignore frees.
----------------
nikic wrote:
Not quite. Frees in the loop are not really a concern here, because they would prevent promotion entirely (by being an unanalyzable write). What this code is about is determining whether it's legal to introduce a speculative store. Dereferenceabiliy is a necessary but not sufficient condition for this, we also need that it is a non-escaped writable object. If this is ensured by `writable`, then we also need to check this condition from LangRef:
> This attribute is only meaningful in conjunction with dereferenceable(N) or another attribute that implies the first N bytes of the pointer argument are dereferenceable.
That's what this separate dereferenceability check is for.
https://github.com/llvm/llvm-project/pull/202589
More information about the llvm-commits
mailing list