Lines Matching defs:GEP
9 // TLDR: replaces llvm.preserve.static.offset + GEP + load / store
70 // with AllowPatial set to true, this handles marked GEP chains
73 // with AllowPatial set to false, this handles marked GEP chains
210 GEPChainInfo &GEP, T *Insn) {
215 Args.push_back(GEP.Members[0]->getPointerOperand());
220 Args.push_back(ConstantInt::get(Int1Ty, GEP.InBounds));
221 Args.append(GEP.Indices.begin(), GEP.Indices.end());
224 static Instruction *makeGEPAndLoad(Module *M, GEPChainInfo &GEP,
227 fillCommonArgs(M->getContext(), Args, GEP, Load);
230 setParamElementType(Call, 0, GEP.SourceElementType);
231 Call->applyMergedLocation(mergeDILocations(GEP.Members), Load->getDebugLoc());
232 Call->setName((*GEP.Members.rbegin())->getName());
244 static Instruction *makeGEPAndStore(Module *M, GEPChainInfo &GEP,
248 fillCommonArgs(M->getContext(), Args, GEP, Store);
252 setParamElementType(Call, 1, GEP.SourceElementType);
255 Call->applyMergedLocation(mergeDILocations(GEP.Members),
283 auto *GEP =
286 GEP->setIsInBounds(getOperandAsUnsigned(Call, 5 + Delta));
287 return GEP;
291 static void reconstructCommon(CallInst *Call, GetElementPtrInst *GEP, T *Insn,
298 GEP->setDebugLoc(Call->getDebugLoc());
305 GetElementPtrInst *GEP = reconstructGEP(Call, 0);
307 auto *Load = new LoadInst(ReturnType, GEP, "",
310 reconstructCommon(Call, GEP, Load, 0);
311 return std::pair{GEP, Load};
316 GetElementPtrInst *GEP = reconstructGEP(Call, 1);
317 auto *Store = new StoreInst(Call->getOperand(0), GEP,
320 reconstructCommon(Call, GEP, Store, 1);
321 return std::pair{GEP, Store};
329 // Given a chain of GEP instructions collect information necessary to
330 // merge this chain as a single GEP instruction of form:
337 if (!all_of(GEPs, [=](GetElementPtrInst *GEP) {
338 return GEP->hasAllConstantIndices();
350 GetElementPtrInst *GEP = *Iter;
351 if (!isZero(*GEP->idx_begin())) {
355 if (!GEP->getSourceElementType() ||
356 GEP->getSourceElementType() != ResultElementType) {
360 Info.InBounds &= GEP->isInBounds();
361 Info.Indices.append(GEP->idx_begin() + 1, GEP->idx_end());
362 Info.Members.push_back(GEP);
363 ResultElementType = GEP->getResultElementType();
369 // Given a chain of GEP instructions collect information necessary to
370 // merge this chain as a single GEP instruction of form:
382 for (GetElementPtrInst *GEP : GEPs) {
383 if (!GEP->accumulateConstantOffset(DL, Offset)) {
387 Info.InBounds &= GEP->isInBounds();
388 Info.Members.push_back(GEP);
409 return GEPs.empty() || all_of(GEPs, [=](GetElementPtrInst *GEP) {
410 return GEP->hasAllZeroIndices();
441 if (auto *GEP = dyn_cast<GetElementPtrInst>(U))
442 return GEP->getPointerOperand() == I;
479 // A DFS traversal of GEP chain trees starting from Root.
481 // Recursion descends through GEP instructions and
493 // - GEPs - GEP instructions for the current branch
496 // - AllowPartial - when true GEP chains that can't be folded are
498 // - StillUsed - set to true if one of the GEP chains could not be
527 auto [GEP, Load] =
529 GEPs.push_back(GEP);
533 delete GEP;
538 auto [GEP, Store] =
540 GEPs.push_back(GEP);
544 delete GEP;
545 } else if (auto *GEP = dyn_cast<GetElementPtrInst>(Insn)) {
546 GEPs.push_back(GEP);
616 if (auto *GEP = dyn_cast<GetElementPtrInst>(U))
617 return GEP->getPointerOperand() == Op;