Lines Matching refs:AI
163 isOnlyCopiedFromConstantGlobal(AllocaInst *AI, in isOnlyCopiedFromConstantGlobal() argument
166 if (isOnlyCopiedFromConstantGlobal(AI, TheCopy, ToDelete)) in isOnlyCopiedFromConstantGlobal()
172 static bool isDereferenceableForAllocaSize(const Value *V, const AllocaInst *AI, in isDereferenceableForAllocaSize() argument
174 if (AI->isArrayAllocation()) in isDereferenceableForAllocaSize()
176 uint64_t AllocaSize = DL.getTypeStoreSize(AI->getAllocatedType()); in isDereferenceableForAllocaSize()
179 return isDereferenceableAndAlignedPointer(V, AI->getAlignment(), in isDereferenceableForAllocaSize()
183 static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) { in simplifyAllocaArraySize() argument
185 if (!AI.isArrayAllocation()) { in simplifyAllocaArraySize()
187 if (AI.getArraySize()->getType()->isIntegerTy(32)) in simplifyAllocaArraySize()
192 AI.setOperand(0, V); in simplifyAllocaArraySize()
193 return &AI; in simplifyAllocaArraySize()
197 if (const ConstantInt *C = dyn_cast<ConstantInt>(AI.getArraySize())) { in simplifyAllocaArraySize()
199 Type *NewTy = ArrayType::get(AI.getAllocatedType(), C->getZExtValue()); in simplifyAllocaArraySize()
200 AllocaInst *New = IC.Builder.CreateAlloca(NewTy, nullptr, AI.getName()); in simplifyAllocaArraySize()
201 New->setAlignment(AI.getAlignment()); in simplifyAllocaArraySize()
213 Type *IdxTy = IC.getDataLayout().getIntPtrType(AI.getType()); in simplifyAllocaArraySize()
222 return IC.replaceInstUsesWith(AI, GEP); in simplifyAllocaArraySize()
226 if (isa<UndefValue>(AI.getArraySize())) in simplifyAllocaArraySize()
227 return IC.replaceInstUsesWith(AI, Constant::getNullValue(AI.getType())); in simplifyAllocaArraySize()
231 Type *IntPtrTy = IC.getDataLayout().getIntPtrType(AI.getType()); in simplifyAllocaArraySize()
232 if (AI.getArraySize()->getType() != IntPtrTy) { in simplifyAllocaArraySize()
233 Value *V = IC.Builder.CreateIntCast(AI.getArraySize(), IntPtrTy, false); in simplifyAllocaArraySize()
234 AI.setOperand(0, V); in simplifyAllocaArraySize()
235 return &AI; in simplifyAllocaArraySize()
342 Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) { in visitAllocaInst() argument
343 if (auto *I = simplifyAllocaArraySize(*this, AI)) in visitAllocaInst()
346 if (AI.getAllocatedType()->isSized()) { in visitAllocaInst()
348 if (AI.getAlignment() == 0) in visitAllocaInst()
349 AI.setAlignment(DL.getPrefTypeAlignment(AI.getAllocatedType())); in visitAllocaInst()
354 if (DL.getTypeAllocSize(AI.getAllocatedType()) == 0) { in visitAllocaInst()
358 if (AI.isArrayAllocation()) { in visitAllocaInst()
359 AI.setOperand(0, ConstantInt::get(AI.getArraySize()->getType(), 1)); in visitAllocaInst()
360 return &AI; in visitAllocaInst()
364 BasicBlock &EntryBlock = AI.getParent()->getParent()->getEntryBlock(); in visitAllocaInst()
366 if (FirstInst != &AI) { in visitAllocaInst()
373 AI.moveBefore(FirstInst); in visitAllocaInst()
374 return &AI; in visitAllocaInst()
386 AI.getAlignment()); in visitAllocaInst()
388 if (AI.getType() != EntryAI->getType()) in visitAllocaInst()
389 return new BitCastInst(EntryAI, AI.getType()); in visitAllocaInst()
390 return replaceInstUsesWith(AI, EntryAI); in visitAllocaInst()
395 if (AI.getAlignment()) { in visitAllocaInst()
403 if (MemTransferInst *Copy = isOnlyCopiedFromConstantGlobal(&AI, ToDelete)) { in visitAllocaInst()
405 Copy->getSource(), AI.getAlignment(), DL, &AI, &AC, &DT); in visitAllocaInst()
406 if (AI.getAlignment() <= SourceAlign && in visitAllocaInst()
407 isDereferenceableForAllocaSize(Copy->getSource(), &AI, DL)) { in visitAllocaInst()
408 LLVM_DEBUG(dbgs() << "Found alloca equal to global: " << AI << '\n'); in visitAllocaInst()
414 auto *DestTy = PointerType::get(AI.getType()->getPointerElementType(), in visitAllocaInst()
418 if (AI.getType()->getPointerAddressSpace() == in visitAllocaInst()
420 Instruction *NewI = replaceInstUsesWith(AI, Cast); in visitAllocaInst()
426 PtrReplacer.replacePointer(AI, Cast); in visitAllocaInst()
435 return visitAllocSite(AI); in visitAllocaInst()
833 if (AllocaInst *AI = dyn_cast<AllocaInst>(P)) { in isObjectSizeLessThanOrEq() local
834 if (!AI->getAllocatedType()->isSized()) in isObjectSizeLessThanOrEq()
837 ConstantInt *CS = dyn_cast<ConstantInt>(AI->getArraySize()); in isObjectSizeLessThanOrEq()
841 uint64_t TypeSize = DL.getTypeAllocSize(AI->getAllocatedType()); in isObjectSizeLessThanOrEq()