[PATCH] D109083: [NFC][PowerPC] Small code refactor in LoopInstrFormPrep
Jinsong Ji via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 1 12:32:32 PDT 2021
jsji created this revision.
jsji added reviewers: PowerPC, shchenz.
Herald added subscribers: kbarton, hiraditya, nemanjai.
jsji requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Avoid some duplicate code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109083
Files:
llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
Index: llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
+++ llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
@@ -269,20 +269,31 @@
return "";
}
-static Value *GetPointerOperand(Value *MemI) {
+static Value *GetPointerOperand(Value *MemI, Type **PtrElementType = nullptr) {
+
+ Value *PtrValue = nullptr;
+ Type *PointerElementType = nullptr;
+
if (LoadInst *LMemI = dyn_cast<LoadInst>(MemI)) {
- return LMemI->getPointerOperand();
+ PtrValue = LMemI->getPointerOperand();
+ PointerElementType = LMemI->getType();
} else if (StoreInst *SMemI = dyn_cast<StoreInst>(MemI)) {
- return SMemI->getPointerOperand();
+ PtrValue = SMemI->getPointerOperand();
+ PointerElementType = SMemI->getValueOperand()->getType();
} else if (IntrinsicInst *IMemI = dyn_cast<IntrinsicInst>(MemI)) {
+ PointerElementType = Type::getInt8Ty(MemI->getContext());
if (IMemI->getIntrinsicID() == Intrinsic::prefetch ||
- IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp)
- return IMemI->getArgOperand(0);
- if (IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp)
- return IMemI->getArgOperand(1);
+ IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) {
+ PtrValue = IMemI->getArgOperand(0);
+ } else if (IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp) {
+ PtrValue = IMemI->getArgOperand(1);
+ }
}
+ /*Get ElementType if PtrElementType is not null.*/
+ if (PtrElementType)
+ *PtrElementType = PointerElementType;
- return nullptr;
+ return PtrValue;
}
bool PPCLoopInstrFormPrep::runOnFunction(Function &F) {
@@ -337,27 +348,14 @@
SmallVector<Bucket, 16> Buckets;
for (const auto &BB : L->blocks())
for (auto &J : *BB) {
- Value *PtrValue;
- Type *PointerElementType;
-
- if (LoadInst *LMemI = dyn_cast<LoadInst>(&J)) {
- PtrValue = LMemI->getPointerOperand();
- PointerElementType = LMemI->getType();
- } else if (StoreInst *SMemI = dyn_cast<StoreInst>(&J)) {
- PtrValue = SMemI->getPointerOperand();
- PointerElementType = SMemI->getValueOperand()->getType();
- } else if (IntrinsicInst *IMemI = dyn_cast<IntrinsicInst>(&J)) {
- PointerElementType = Type::getInt8Ty(J.getContext());
- if (IMemI->getIntrinsicID() == Intrinsic::prefetch ||
- IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) {
- PtrValue = IMemI->getArgOperand(0);
- } else if (IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp) {
- PtrValue = IMemI->getArgOperand(1);
- } else continue;
- } else continue;
-
- unsigned PtrAddrSpace = PtrValue->getType()->getPointerAddressSpace();
- if (PtrAddrSpace)
+ Value *PtrValue = nullptr;
+ Type *PointerElementType = nullptr;
+ PtrValue = GetPointerOperand(&J, &PointerElementType);
+
+ if (!PtrValue)
+ continue;
+
+ if (PtrValue->getType()->getPointerAddressSpace())
continue;
if (L->isLoopInvariant(PtrValue))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109083.370026.patch
Type: text/x-patch
Size: 3119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210901/bf1c80cd/attachment.bin>
More information about the llvm-commits
mailing list