[llvm] 35b4f83 - InferAddressSpaces: Simplify check of volatile allowed

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 4 22:30:26 PDT 2024


Author: Matt Arsenault
Date: 2024-08-05T09:30:08+04:00
New Revision: 35b4f8374586e099215f1275c8d840f54b20869d

URL: https://github.com/llvm/llvm-project/commit/35b4f8374586e099215f1275c8d840f54b20869d
DIFF: https://github.com/llvm/llvm-project/commit/35b4f8374586e099215f1275c8d840f54b20869d.diff

LOG: InferAddressSpaces: Simplify check of volatile allowed

Avoid redundant dyn_cast to instruction before chain of dyn_cast
to specific instructions.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index 6b9566f1ae461..830c15249582c 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -1011,25 +1011,22 @@ static bool isSimplePointerUseValidToReplace(const TargetTransformInfo &TTI,
                                              Use &U, unsigned AddrSpace) {
   User *Inst = U.getUser();
   unsigned OpNo = U.getOperandNo();
-  bool VolatileIsAllowed = false;
-  if (auto *I = dyn_cast<Instruction>(Inst))
-    VolatileIsAllowed = TTI.hasVolatileVariant(I, AddrSpace);
 
   if (auto *LI = dyn_cast<LoadInst>(Inst))
     return OpNo == LoadInst::getPointerOperandIndex() &&
-           (VolatileIsAllowed || !LI->isVolatile());
+           (!LI->isVolatile() || TTI.hasVolatileVariant(LI, AddrSpace));
 
   if (auto *SI = dyn_cast<StoreInst>(Inst))
     return OpNo == StoreInst::getPointerOperandIndex() &&
-           (VolatileIsAllowed || !SI->isVolatile());
+           (!SI->isVolatile() || TTI.hasVolatileVariant(SI, AddrSpace));
 
   if (auto *RMW = dyn_cast<AtomicRMWInst>(Inst))
     return OpNo == AtomicRMWInst::getPointerOperandIndex() &&
-           (VolatileIsAllowed || !RMW->isVolatile());
+           (!RMW->isVolatile() || TTI.hasVolatileVariant(RMW, AddrSpace));
 
   if (auto *CmpX = dyn_cast<AtomicCmpXchgInst>(Inst))
     return OpNo == AtomicCmpXchgInst::getPointerOperandIndex() &&
-           (VolatileIsAllowed || !CmpX->isVolatile());
+           (!CmpX->isVolatile() || TTI.hasVolatileVariant(CmpX, AddrSpace));
 
   return false;
 }


        


More information about the llvm-commits mailing list