[llvm] 8671191 - [NFC][PowerPC] Small code refactor in LoopInstrFormPrep
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 1 20:26:01 PDT 2021
Author: Jinsong Ji
Date: 2021-09-02T03:16:01Z
New Revision: 8671191d26d4dc46f061387fe7db863634124d97
URL: https://github.com/llvm/llvm-project/commit/8671191d26d4dc46f061387fe7db863634124d97
DIFF: https://github.com/llvm/llvm-project/commit/8671191d26d4dc46f061387fe7db863634124d97.diff
LOG: [NFC][PowerPC] Small code refactor in LoopInstrFormPrep
Avoid some duplicate code.
Reviewed By: #powerpc, shchenz
Differential Revision: https://reviews.llvm.org/D109083
Added:
Modified:
llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp b/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
index b69e9f79719b..016aa4cbba8b 100644
--- a/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
+++ b/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
@@ -269,20 +269,32 @@ static std::string getInstrName(const Value *I, StringRef Suffix) {
return "";
}
-static Value *GetPointerOperand(Value *MemI) {
+static Value *getPointerOperandAndType(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) {
@@ -309,7 +321,7 @@ bool PPCLoopInstrFormPrep::runOnFunction(Function &F) {
void PPCLoopInstrFormPrep::addOneCandidate(Instruction *MemI, const SCEV *LSCEV,
SmallVector<Bucket, 16> &Buckets,
unsigned MaxCandidateNum) {
- assert((MemI && GetPointerOperand(MemI)) &&
+ assert((MemI && getPointerOperandAndType(MemI)) &&
"Candidate should be a memory instruction.");
assert(LSCEV && "Invalid SCEV for Ptr value.");
bool FoundBucket = false;
@@ -337,27 +349,14 @@ SmallVector<Bucket, 16> PPCLoopInstrFormPrep::collectCandidates(
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 = getPointerOperandAndType(&J, &PointerElementType);
+
+ if (!PtrValue)
+ continue;
+
+ if (PtrValue->getType()->getPointerAddressSpace())
continue;
if (L->isLoopInvariant(PtrValue))
@@ -505,7 +504,7 @@ bool PPCLoopInstrFormPrep::rewriteLoadStores(Loop *L, Bucket &BucketChain,
// The instruction corresponding to the Bucket's BaseSCEV must be the first
// in the vector of elements.
Instruction *MemI = BucketChain.Elements.begin()->Instr;
- Value *BasePtr = GetPointerOperand(MemI);
+ Value *BasePtr = getPointerOperandAndType(MemI);
assert(BasePtr && "No pointer operand");
Type *I8Ty = Type::getInt8Ty(MemI->getParent()->getContext());
@@ -627,7 +626,7 @@ bool PPCLoopInstrFormPrep::rewriteLoadStores(Loop *L, Bucket &BucketChain,
for (auto I = std::next(BucketChain.Elements.begin()),
IE = BucketChain.Elements.end(); I != IE; ++I) {
- Value *Ptr = GetPointerOperand(I->Instr);
+ Value *Ptr = getPointerOperandAndType(I->Instr);
assert(Ptr && "No pointer operand");
if (NewPtrs.count(Ptr))
continue;
More information about the llvm-commits
mailing list