[llvm] [SimplifyCFG] Use isWritableObject() API (PR #110127)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 08:17:23 PDT 2024


================
@@ -3057,16 +3058,16 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB,
     if (auto *LI = dyn_cast<LoadInst>(&CurI)) {
       if (LI->getPointerOperand() == StorePtr && LI->getType() == StoreTy &&
           LI->isSimple() && LI->getAlign() >= StoreToHoist->getAlign()) {
-        // Local objects (created by an `alloca` instruction) are always
-        // writable, so once we are past a read from a location it is valid to
-        // also write to that same location.
-        // If the address of the local object never escapes the function, that
-        // means it's never concurrently read or written, hence moving the store
-        // from under the condition will not introduce a data race.
-        auto *AI = dyn_cast<AllocaInst>(getUnderlyingObject(StorePtr));
-        if (AI && !PointerMayBeCaptured(AI, false, true))
+        Value *Obj = getUnderlyingObject(StorePtr);
+        bool ExplicitlyDereferenceableOnly;
+        if (isWritableObject(Obj, ExplicitlyDereferenceableOnly) &&
+            !PointerMayBeCaptured(Obj, false, true) &&
----------------
goldsteinn wrote:

nit: While you at it:
`PointerMayBeCaptured(Obj, /*ReturnCaptures=*/false, /*StoreCaptures=*/true)`

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


More information about the llvm-commits mailing list