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
This commit is contained in:
parent
9d28c26d77
commit
dd1d3df524
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -257,5 +257,4 @@ define void @test20() {
|
|||
ret void
|
||||
}
|
||||
; CHECK: @test20
|
||||
; CHECK-NOT: store
|
||||
; CHECK: ret void
|
||||
; CHECK-NEXT: ret void
|
||||
|
|
Loading…
Reference in New Issue