diff --git a/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp b/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp --- a/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp +++ b/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(MemI)) { - return LMemI->getPointerOperand(); + PtrValue = LMemI->getPointerOperand(); + PointerElementType = LMemI->getType(); } else if (StoreInst *SMemI = dyn_cast(MemI)) { - return SMemI->getPointerOperand(); + PtrValue = SMemI->getPointerOperand(); + PointerElementType = SMemI->getValueOperand()->getType(); } else if (IntrinsicInst *IMemI = dyn_cast(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 Buckets; for (const auto &BB : L->blocks()) for (auto &J : *BB) { - Value *PtrValue; - Type *PointerElementType; - - if (LoadInst *LMemI = dyn_cast(&J)) { - PtrValue = LMemI->getPointerOperand(); - PointerElementType = LMemI->getType(); - } else if (StoreInst *SMemI = dyn_cast(&J)) { - PtrValue = SMemI->getPointerOperand(); - PointerElementType = SMemI->getValueOperand()->getType(); - } else if (IntrinsicInst *IMemI = dyn_cast(&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))