[llvm-commits] [llvm] r156553 - in /llvm/trunk: lib/Transforms/Scalar/DeadStoreElimination.cpp lib/Transforms/Utils/Local.cpp test/Transforms/DeadStoreElimination/simple.ll
Nuno Lopes
nunoplopes at sapo.pt
Thu May 10 10:14:00 PDT 2012
Author: nlopes
Date: Thu May 10 12:14:00 2012
New Revision: 156553
URL: http://llvm.org/viewvc/llvm-project?rev=156553&view=rev
Log:
teach DSE and isInstructionTriviallyDead() about calloc
Modified:
llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll
Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=156553&r1=156552&r2=156553&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Thu May 10 12:14:00 2012
@@ -282,6 +282,12 @@
return C->getZExtValue();
}
+ if (const CallInst *CI = extractCallocCall(V)) {
+ if (const ConstantInt *C1 = dyn_cast<ConstantInt>(CI->getArgOperand(0)))
+ if (const ConstantInt *C2 = dyn_cast<ConstantInt>(CI->getArgOperand(1)))
+ return (C1->getValue() * C2->getValue()).getZExtValue();
+ }
+
if (TD == 0)
return AliasAnalysis::UnknownSize;
@@ -704,9 +710,11 @@
// Okay, so these are dead heap objects, but if the pointer never escapes
// then it's leaked by this function anyways.
- if (CallInst *CI = extractMallocCall(I))
- if (!PointerMayBeCaptured(CI, true, true))
- DeadStackObjects.insert(CI);
+ CallInst *CI = extractMallocCall(I);
+ if (!CI)
+ CI = extractCallocCall(I);
+ if (CI && !PointerMayBeCaptured(CI, true, true))
+ DeadStackObjects.insert(CI);
}
// Treat byval arguments the same, stores to them are dead at the end of the
@@ -759,6 +767,11 @@
continue;
}
+ if (CallInst *CI = extractCallocCall(BBI)) {
+ DeadStackObjects.erase(CI);
+ continue;
+ }
+
if (CallSite CS = cast<Value>(BBI)) {
// If this call does not access memory, it can't be loading any of our
// pointers.
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=156553&r1=156552&r2=156553&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Thu May 10 12:14:00 2012
@@ -260,7 +260,7 @@
return isa<UndefValue>(II->getArgOperand(1));
}
- if (extractMallocCall(I)) return true;
+ if (extractMallocCall(I) || extractCallocCall(I)) return true;
if (CallInst *CI = isFreeCall(I))
if (Constant *C = dyn_cast<Constant>(CI->getArgOperand(0)))
Modified: llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll?rev=156553&r1=156552&r2=156553&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll (original)
+++ llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll Thu May 10 12:14:00 2012
@@ -164,7 +164,7 @@
}
declare noalias i8* @malloc(i32)
-
+declare noalias i8* @calloc(i32, i32)
define void @test14(i32* %Q) {
@@ -258,3 +258,11 @@
}
; CHECK: @test20
; CHECK-NEXT: ret void
+
+; CHECK: @test21
+define void @test21() {
+ %m = call i8* @calloc(i32 9, i32 7)
+ store i8 0, i8* %m
+; CHECK-NEXT: ret void
+ ret void
+}
More information about the llvm-commits
mailing list