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
209 GEPChainInfo &GEP, T *Insn) {
214 Args.push_back(GEP.Members[0]->getPointerOperand());
219 Args.push_back(ConstantInt::get(Int1Ty, GEP.InBounds));
220 Args.append(GEP.Indices.begin(), GEP.Indices.end());
223 static Instruction *makeGEPAndLoad(Module *M, GEPChainInfo &GEP,
226 fillCommonArgs(M->getContext(), Args, GEP, Load);
229 setParamElementType(Call, 0, GEP.SourceElementType);
230 Call->applyMergedLocation(mergeDILocations(GEP.Members), Load->getDebugLoc());
231 Call->setName((*GEP.Members.rbegin())->getName());
243 static Instruction *makeGEPAndStore(Module *M, GEPChainInfo &GEP,
247 fillCommonArgs(M->getContext(), Args, GEP, Store);
251 setParamElementType(Call, 1, GEP.SourceElementType);
254 Call->applyMergedLocation(mergeDILocations(GEP.Members),
282 auto *GEP =
285 GEP->setIsInBounds(getOperandAsUnsigned(Call, 5 + Delta));
286 return GEP;
290 static void reconstructCommon(CallInst *Call, GetElementPtrInst *GEP, T *Insn,
297 GEP->setDebugLoc(Call->getDebugLoc());
304 GetElementPtrInst *GEP = reconstructGEP(Call, 0);
306 auto *Load = new LoadInst(ReturnType, GEP, "",
309 reconstructCommon(Call, GEP, Load, 0);
310 return std::pair{GEP, Load};
315 GetElementPtrInst *GEP = reconstructGEP(Call, 1);
316 auto *Store = new StoreInst(Call->getOperand(0), GEP,
319 reconstructCommon(Call, GEP, Store, 1);
320 return std::pair{GEP, Store};
328 // Given a chain of GEP instructions collect information necessary to
329 // merge this chain as a single GEP instruction of form:
336 if (!all_of(GEPs, [=](GetElementPtrInst *GEP) {
337 return GEP->hasAllConstantIndices();
349 GetElementPtrInst *GEP = *Iter;
350 if (!isZero(*GEP->idx_begin())) {
354 if (!GEP->getSourceElementType() ||
355 GEP->getSourceElementType() != ResultElementType) {
359 Info.InBounds &= GEP->isInBounds();
360 Info.Indices.append(GEP->idx_begin() + 1, GEP->idx_end());
361 Info.Members.push_back(GEP);
362 ResultElementType = GEP->getResultElementType();
368 // Given a chain of GEP instructions collect information necessary to
369 // merge this chain as a single GEP instruction of form:
381 for (GetElementPtrInst *GEP : GEPs) {
382 if (!GEP->accumulateConstantOffset(DL, Offset)) {
386 Info.InBounds &= GEP->isInBounds();
387 Info.Members.push_back(GEP);
408 return GEPs.empty() || all_of(GEPs, [=](GetElementPtrInst *GEP) {
409 return GEP->hasAllZeroIndices();
440 if (auto *GEP = dyn_cast<GetElementPtrInst>(U))
441 return GEP->getPointerOperand() == I;
478 // A DFS traversal of GEP chain trees starting from Root.
480 // Recursion descends through GEP instructions and
492 // - GEPs - GEP instructions for the current branch
495 // - AllowPartial - when true GEP chains that can't be folded are
497 // - StillUsed - set to true if one of the GEP chains could not be
526 auto [GEP, Load] =
528 GEPs.push_back(GEP);
532 delete GEP;
537 auto [GEP, Store] =
539 GEPs.push_back(GEP);
543 delete GEP;
544 } else if (auto *GEP = dyn_cast<GetElementPtrInst>(Insn)) {
545 GEPs.push_back(GEP);
615 if (auto *GEP = dyn_cast<GetElementPtrInst>(U))
616 return GEP->getPointerOperand() == Op;