From ddd9ec667a2e3ec241f11dbb8368600dcf432eb4 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 6 Jan 2022 14:44:39 +0100 Subject: [PATCH] [LICM] Update comments related to escape check (NFC) The comments here were outdated and a bit confusing without the knowledge that we're only guarding against reads on unwind. --- llvm/lib/Transforms/Scalar/LICM.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 80ed671..ebb2520 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1923,9 +1923,9 @@ bool isNotCapturedBeforeOrInLoop(const Value *V, const Loop *L, L->getHeader()->getTerminator(), DT); } -/// Return true iff we can prove that a caller of this function can not inspect -/// the contents of the provided object in a well defined program. -bool isKnownNonEscaping(Value *Object, const Loop *L, DominatorTree *DT) { +/// Return true if we can prove that a caller cannot inspect the object if an +/// unwind occurs inside the loop. +bool isNotVisibleOnUnwind(Value *Object, const Loop *L, DominatorTree *DT) { if (isa(Object)) // Since the alloca goes out of scope, we know the caller can't retain a // reference to it and be well defined. Thus, we don't need to check for @@ -1933,12 +1933,12 @@ bool isKnownNonEscaping(Value *Object, const Loop *L, DominatorTree *DT) { return true; // For all other objects we need to know that the caller can't possibly - // have gotten a reference to the object. There are two components of - // that: - // 1) Object can't be escaped by this function. This is what - // PointerMayBeCaptured checks. - // 2) Object can't have been captured at definition site. For this, we - // need to know the return value is noalias. + // have gotten a reference to the object prior to an unwind in the loop. + // There are two components of that: + // 1) Object can't have been captured prior to the definition site. + // For this, we need to know the return value is noalias. + // 1) Object can't be captured before or inside the loop. This is what + // isNotCapturedBeforeOrInLoop() checks. return isNoAliasCall(Object) && isNotCapturedBeforeOrInLoop(Object, L, DT); } @@ -2026,7 +2026,7 @@ bool llvm::promoteLoopAccessesToScalars( // this by proving that the caller can't have a reference to the object // after return and thus can't possibly load from the object. Value *Object = getUnderlyingObject(SomePtr); - if (!isKnownNonEscaping(Object, CurLoop, DT)) + if (!isNotVisibleOnUnwind(Object, CurLoop, DT)) return false; // Subtlety: Alloca's aren't visible to callers, but *are* potentially // visible to other threads if captured and used during their lifetimes. -- 2.7.4