Skip to content

Commit 35b4f83

Browse files
committed
InferAddressSpaces: Simplify check of volatile allowed
Avoid redundant dyn_cast to instruction before chain of dyn_cast to specific instructions.
1 parent ebeb6b2 commit 35b4f83

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,25 +1011,22 @@ static bool isSimplePointerUseValidToReplace(const TargetTransformInfo &TTI,
10111011
Use &U, unsigned AddrSpace) {
10121012
User *Inst = U.getUser();
10131013
unsigned OpNo = U.getOperandNo();
1014-
bool VolatileIsAllowed = false;
1015-
if (auto *I = dyn_cast<Instruction>(Inst))
1016-
VolatileIsAllowed = TTI.hasVolatileVariant(I, AddrSpace);
10171014

10181015
if (auto *LI = dyn_cast<LoadInst>(Inst))
10191016
return OpNo == LoadInst::getPointerOperandIndex() &&
1020-
(VolatileIsAllowed || !LI->isVolatile());
1017+
(!LI->isVolatile() || TTI.hasVolatileVariant(LI, AddrSpace));
10211018

10221019
if (auto *SI = dyn_cast<StoreInst>(Inst))
10231020
return OpNo == StoreInst::getPointerOperandIndex() &&
1024-
(VolatileIsAllowed || !SI->isVolatile());
1021+
(!SI->isVolatile() || TTI.hasVolatileVariant(SI, AddrSpace));
10251022

10261023
if (auto *RMW = dyn_cast<AtomicRMWInst>(Inst))
10271024
return OpNo == AtomicRMWInst::getPointerOperandIndex() &&
1028-
(VolatileIsAllowed || !RMW->isVolatile());
1025+
(!RMW->isVolatile() || TTI.hasVolatileVariant(RMW, AddrSpace));
10291026

10301027
if (auto *CmpX = dyn_cast<AtomicCmpXchgInst>(Inst))
10311028
return OpNo == AtomicCmpXchgInst::getPointerOperandIndex() &&
1032-
(VolatileIsAllowed || !CmpX->isVolatile());
1029+
(!CmpX->isVolatile() || TTI.hasVolatileVariant(CmpX, AddrSpace));
10331030

10341031
return false;
10351032
}

0 commit comments

Comments
 (0)