aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-10-24 04:35:36 +0000
committerStephen Hines <srhines@google.com>2011-11-14 09:11:06 -0800
commitcc4c43f648a8021c7dc410a090559e9733fc0bbb (patch)
treef14f101b9e6d3e4e8f223e00c408f30a14eec3f9 /lib/Transforms/Utils/Local.cpp
parent46380baa001efb30f0e4ea0c9f9bd444f2bad9ae (diff)
downloadexternal_llvm-cc4c43f648a8021c7dc410a090559e9733fc0bbb.tar.gz
external_llvm-cc4c43f648a8021c7dc410a090559e9733fc0bbb.tar.bz2
external_llvm-cc4c43f648a8021c7dc410a090559e9733fc0bbb.zip
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
Diffstat (limited to 'lib/Transforms/Utils/Local.cpp')
-rw-r--r--lib/Transforms/Utils/Local.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 7034feb227..134ab71050 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<UndefValue>(II->getArgOperand(1));
}
+
+ if (extractMallocCall(I)) return true;
+
+ if (CallInst *CI = isFreeCall(I))
+ if (Constant *C = dyn_cast<Constant>(CI->getArgOperand(0)))
+ return C->isNullValue() || isa<UndefValue>(C);
+
return false;
}