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 @@ -191,11 +191,11 @@ /// Collect condition matched(\p isValidCandidate() returns true) /// candidates in Loop \p L. - SmallVector - collectCandidates(Loop *L, - std::function - isValidCandidate, - unsigned MaxCandidateNum); + SmallVector collectCandidates( + Loop *L, + std::function + isValidCandidate, + unsigned MaxCandidateNum); /// Add a candidate to candidates \p Buckets. void addOneCandidate(Instruction *MemI, const SCEV *LSCEV, @@ -331,18 +331,23 @@ SmallVector PPCLoopInstrFormPrep::collectCandidates( Loop *L, - std::function isValidCandidate, + std::function + isValidCandidate, unsigned MaxCandidateNum) { 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); @@ -363,7 +368,7 @@ if (!LARSCEV || LARSCEV->getLoop() != L) continue; - if (isValidCandidate(&J, PtrValue)) + if (isValidCandidate(&J, PtrValue, PointerElementType)) addOneCandidate(&J, LSCEV, Buckets, MaxCandidateNum); } return Buckets; @@ -820,12 +825,11 @@ } // Check if a load/store has update form. This lambda is used by function // collectCandidates which can collect candidates for types defined by lambda. - auto isUpdateFormCandidate = [&] (const Instruction *I, - const Value *PtrValue) { + auto isUpdateFormCandidate = [&](const Instruction *I, const Value *PtrValue, + const Type *PointerElementType) { assert((PtrValue && I) && "Invalid parameter!"); // There are no update forms for Altivec vector load/stores. - if (ST && ST->hasAltivec() && - PtrValue->getType()->getPointerElementType()->isVectorTy()) + if (ST && ST->hasAltivec() && PointerElementType->isVectorTy()) return false; // There are no update forms for P10 lxvp/stxvp intrinsic. auto *II = dyn_cast(I); @@ -837,7 +841,7 @@ // fits in a 16-bit signed field but isn't a multiple of 4, it will be // useless and possible to break some original well-form addressing mode // to make this pre-inc prep for it. - if (PtrValue->getType()->getPointerElementType()->isIntegerTy(64)) { + if (PointerElementType->isIntegerTy(64)) { const SCEV *LSCEV = SE->getSCEVAtScope(const_cast(PtrValue), L); const SCEVAddRecExpr *LARSCEV = dyn_cast(LSCEV); if (!LARSCEV || LARSCEV->getLoop() != L) @@ -851,13 +855,13 @@ } return true; }; - + // Check if a load/store has DS form. - auto isDSFormCandidate = [] (const Instruction *I, const Value *PtrValue) { + auto isDSFormCandidate = [](const Instruction *I, const Value *PtrValue, + const Type *PointerElementType) { assert((PtrValue && I) && "Invalid parameter!"); if (isa(I)) return false; - Type *PointerElementType = PtrValue->getType()->getPointerElementType(); return (PointerElementType->isIntegerTy(64)) || (PointerElementType->isFloatTy()) || (PointerElementType->isDoubleTy()) || @@ -867,7 +871,8 @@ }; // Check if a load/store has DQ form. - auto isDQFormCandidate = [&] (const Instruction *I, const Value *PtrValue) { + auto isDQFormCandidate = [&](const Instruction *I, const Value *PtrValue, + const Type *PointerElementType) { assert((PtrValue && I) && "Invalid parameter!"); // Check if it is a P10 lxvp/stxvp intrinsic. auto *II = dyn_cast(I); @@ -875,8 +880,7 @@ return II->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp || II->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp; // Check if it is a P9 vector load/store. - return ST && ST->hasP9Vector() && - (PtrValue->getType()->getPointerElementType()->isVectorTy()); + return ST && ST->hasP9Vector() && (PointerElementType->isVectorTy()); }; // intrinsic for update form.