llvm.org GIT mirror llvm / e548744
teach DSE and isInstructionTriviallyDead() about calloc git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156553 91177308-0d34-0410-b5e6-96231b3b80d8 Nuno Lopes 7 years ago
3 changed file(s) with 26 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
279279 if (const CallInst *CI = extractMallocCall(V)) {
280280 if (const ConstantInt *C = dyn_cast(CI->getArgOperand(0)))
281281 return C->getZExtValue();
282 }
283
284 if (const CallInst *CI = extractCallocCall(V)) {
285 if (const ConstantInt *C1 = dyn_cast(CI->getArgOperand(0)))
286 if (const ConstantInt *C2 = dyn_cast(CI->getArgOperand(1)))
287 return (C1->getValue() * C2->getValue()).getZExtValue();
282288 }
283289
284290 if (TD == 0)
703709
704710 // Okay, so these are dead heap objects, but if the pointer never escapes
705711 // then it's leaked by this function anyways.
706 if (CallInst *CI = extractMallocCall(I))
707 if (!PointerMayBeCaptured(CI, true, true))
708 DeadStackObjects.insert(CI);
712 CallInst *CI = extractMallocCall(I);
713 if (!CI)
714 CI = extractCallocCall(I);
715 if (CI && !PointerMayBeCaptured(CI, true, true))
716 DeadStackObjects.insert(CI);
709717 }
710718
711719 // Treat byval arguments the same, stores to them are dead at the end of the
754762 }
755763
756764 if (CallInst *CI = extractMallocCall(BBI)) {
765 DeadStackObjects.erase(CI);
766 continue;
767 }
768
769 if (CallInst *CI = extractCallocCall(BBI)) {
757770 DeadStackObjects.erase(CI);
758771 continue;
759772 }
259259 return isa(II->getArgOperand(1));
260260 }
261261
262 if (extractMallocCall(I)) return true;
262 if (extractMallocCall(I) || extractCallocCall(I)) return true;
263263
264264 if (CallInst *CI = isFreeCall(I))
265265 if (Constant *C = dyn_cast(CI->getArgOperand(0)))
163163 }
164164
165165 declare noalias i8* @malloc(i32)
166
166 declare noalias i8* @calloc(i32, i32)
167167
168168
169169 define void @test14(i32* %Q) {
257257 }
258258 ; CHECK: @test20
259259 ; CHECK-NEXT: ret void
260
261 ; CHECK: @test21
262 define void @test21() {
263 %m = call i8* @calloc(i32 9, i32 7)
264 store i8 0, i8* %m
265 ; CHECK-NEXT: ret void
266 ret void
267 }