From f278734bf1dd8db64b62e009ce77432b62420684 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 6 Mar 2021 15:58:18 +0100 Subject: [PATCH] [Loads] Restructure getAvailableLoadStore implementation (NFC) Separate out some conditions with early exits, to make it easier to support additional cases. --- llvm/lib/Analysis/Loads.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index d82ed02a67bc..88e4c723331a 100644 --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -469,14 +469,16 @@ static Value *getAvailableLoadStore(Instruction *Inst, Value *Ptr, // (This is true even if the load is volatile or atomic, although // those cases are unlikely.) if (LoadInst *LI = dyn_cast(Inst)) { - if (AreEquivalentAddressValues( - LI->getPointerOperand()->stripPointerCasts(), Ptr) && - CastInst::isBitOrNoopPointerCastable(LI->getType(), AccessTy, DL)) { - // We can value forward from an atomic to a non-atomic, but not the - // other way around. - if (LI->isAtomic() < AtLeastAtomic) - return nullptr; + // We can value forward from an atomic to a non-atomic, but not the + // other way around. + if (LI->isAtomic() < AtLeastAtomic) + return nullptr; + Value *LoadPtr = LI->getPointerOperand()->stripPointerCasts(); + if (!AreEquivalentAddressValues(LoadPtr, Ptr)) + return nullptr; + + if (CastInst::isBitOrNoopPointerCastable(LI->getType(), AccessTy, DL)) { if (IsLoadCSE) *IsLoadCSE = true; return LI; @@ -487,18 +489,20 @@ static Value *getAvailableLoadStore(Instruction *Inst, Value *Ptr, // (This is true even if the store is volatile or atomic, although // those cases are unlikely.) if (StoreInst *SI = dyn_cast(Inst)) { - Value *StorePtr = SI->getPointerOperand()->stripPointerCasts(); - if (AreEquivalentAddressValues(StorePtr, Ptr) && - CastInst::isBitOrNoopPointerCastable(SI->getValueOperand()->getType(), - AccessTy, DL)) { - // We can value forward from an atomic to a non-atomic, but not the - // other way around. - if (SI->isAtomic() < AtLeastAtomic) - return nullptr; + // We can value forward from an atomic to a non-atomic, but not the + // other way around. + if (SI->isAtomic() < AtLeastAtomic) + return nullptr; + Value *StorePtr = SI->getPointerOperand()->stripPointerCasts(); + if (!AreEquivalentAddressValues(StorePtr, Ptr)) + return nullptr; + + Value *Val = SI->getValueOperand(); + if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL)) { if (IsLoadCSE) *IsLoadCSE = false; - return SI->getOperand(0); + return Val; } }