mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 23:24:34 +00:00
remove calls to calloc if the allocated memory is not used (it was already being done for malloc)
fix a few typos found by Chad in my previous commit git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156110 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -182,7 +182,7 @@ Value *llvm::getMallocArraySize(CallInst *CI, const TargetData *TD,
|
|||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// clloc Call Utility Functions.
|
// calloc Call Utility Functions.
|
||||||
//
|
//
|
||||||
|
|
||||||
static bool isCallocCall(const CallInst *CI) {
|
static bool isCallocCall(const CallInst *CI) {
|
||||||
@ -197,7 +197,7 @@ static bool isCallocCall(const CallInst *CI) {
|
|||||||
|
|
||||||
// Check malloc prototype.
|
// Check malloc prototype.
|
||||||
// FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
|
// FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
|
||||||
// attribute will exist.
|
// attribute exists.
|
||||||
FunctionType *FTy = Callee->getFunctionType();
|
FunctionType *FTy = Callee->getFunctionType();
|
||||||
return FTy->getReturnType() == Type::getInt8PtrTy(FTy->getContext()) &&
|
return FTy->getReturnType() == Type::getInt8PtrTy(FTy->getContext()) &&
|
||||||
FTy->getNumParams() == 2 &&
|
FTy->getNumParams() == 2 &&
|
||||||
|
@ -172,7 +172,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
|
|||||||
Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||||
if (isFreeCall(&CI))
|
if (isFreeCall(&CI))
|
||||||
return visitFree(CI);
|
return visitFree(CI);
|
||||||
if (isMalloc(&CI))
|
if (extractMallocCall(&CI) || extractCallocCall(&CI))
|
||||||
return visitMalloc(CI);
|
return visitMalloc(CI);
|
||||||
|
|
||||||
// If the caller function is nounwind, mark the call as nounwind, even if the
|
// If the caller function is nounwind, mark the call as nounwind, even if the
|
||||||
|
@ -165,7 +165,7 @@ define i32 @test8() {
|
|||||||
%alloc = call noalias i8* @calloc(i32 5, i32 7) nounwind
|
%alloc = call noalias i8* @calloc(i32 5, i32 7) nounwind
|
||||||
%gep = getelementptr inbounds i8* %alloc, i32 5
|
%gep = getelementptr inbounds i8* %alloc, i32 5
|
||||||
%objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false) nounwind readonly
|
%objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false) nounwind readonly
|
||||||
; CHECK: ret i32 30
|
; CHECK-NEXT: ret i32 30
|
||||||
ret i32 %objsize
|
ret i32 %objsize
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +175,6 @@ define i32 @test9() {
|
|||||||
%alloc = call noalias i8* @calloc(i32 100000000, i32 100000000) nounwind
|
%alloc = call noalias i8* @calloc(i32 100000000, i32 100000000) nounwind
|
||||||
%gep = getelementptr inbounds i8* %alloc, i32 2
|
%gep = getelementptr inbounds i8* %alloc, i32 2
|
||||||
%objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 true) nounwind readonly
|
%objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 true) nounwind readonly
|
||||||
; CHECK: ret i32 0
|
; CHECK-NEXT: ret i32 0
|
||||||
ret i32 %objsize
|
ret i32 %objsize
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user