From: Nick Lewycky Date: Mon, 24 Oct 2011 04:35:36 +0000 (+0000) Subject: A dead malloc, a free(NULL) and a free(undef) are all trivially dead X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=4a3935c27e5315081844a5b7ae1f7097efc234b0;p=oota-llvm.git A dead malloc, a free(NULL) and a free(undef) are all trivially dead instructions. This doesn't introduce any optimizations we weren't doing before (except potentially due to pass ordering issues), now passes will eliminate them sooner as part of their own cleanups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142787 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 7034feb227a..134ab71050a 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -28,6 +28,7 @@ #include "llvm/Analysis/DIBuilder.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/InstructionSimplify.h" +#include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/ProfileInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Target/TargetData.h" @@ -257,6 +258,13 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) { II->getIntrinsicID() == Intrinsic::lifetime_end) return isa(II->getArgOperand(1)); } + + if (extractMallocCall(I)) return true; + + if (CallInst *CI = isFreeCall(I)) + if (Constant *C = dyn_cast(CI->getArgOperand(0))) + return C->isNullValue() || isa(C); + return false; } diff --git a/test/Transforms/DeadStoreElimination/simple.ll b/test/Transforms/DeadStoreElimination/simple.ll index 1703ee961f5..81eb5a8c705 100644 --- a/test/Transforms/DeadStoreElimination/simple.ll +++ b/test/Transforms/DeadStoreElimination/simple.ll @@ -257,5 +257,4 @@ define void @test20() { ret void } ; CHECK: @test20 -; CHECK-NOT: store -; CHECK: ret void +; CHECK-NEXT: ret void