summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-10-24 04:35:36 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-10-24 04:35:36 +0000
commitdd1d3df524f45d0f26274c4e777ebd01419ced67 (patch)
tree942dcb18ce323312e2122ac3774ae749d1147efc /llvm/lib/Transforms/Utils/Local.cpp
parent9d28c26d77af460bec980ebcbc0e9ca13ad65f4a (diff)
downloadbcm5719-llvm-dd1d3df524f45d0f26274c4e777ebd01419ced67.tar.gz
bcm5719-llvm-dd1d3df524f45d0f26274c4e777ebd01419ced67.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. llvm-svn: 142787
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 7034feb227a..134ab71050a 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud