From: Owen Anderson Date: Sun, 12 Oct 2008 08:10:46 +0000 (+0000) Subject: Add special-case code to allow null-guards on calls to malloc. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b5cf048fdf42fea53182523ad815181a8af068a0;p=oota-llvm.git Add special-case code to allow null-guards on calls to malloc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57413 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/EscapeAnalysis.cpp b/lib/Analysis/EscapeAnalysis.cpp index 43bad29fb7d..94e953d460a 100644 --- a/lib/Analysis/EscapeAnalysis.cpp +++ b/lib/Analysis/EscapeAnalysis.cpp @@ -13,6 +13,7 @@ #define DEBUG_TYPE "escape-analysis" #include "llvm/Analysis/EscapeAnalysis.h" +#include "llvm/Constants.h" #include "llvm/Module.h" #include "llvm/Support/InstIterator.h" #include "llvm/ADT/SmallPtrSet.h" @@ -112,8 +113,21 @@ bool EscapeAnalysis::escapes(Value* A) { worklist.pop_back(); if (Instruction* I = dyn_cast(curr)) - if (EscapePoints.count(I)) - return true; + if (EscapePoints.count(I)) { + BranchInst* B = dyn_cast(I); + if (!B) return true; + Value* condition = B->getCondition(); + ICmpInst* C = dyn_cast(condition); + if (!C) return true; + Value* O1 = C->getOperand(0); + Value* O2 = C->getOperand(1); + if (isa(O1->stripPointerCasts())) { + if (!isa(O2)) return true; + } else if(isa(O2->stripPointerCasts())) { + if (!isa(O1)) return true; + } else + return true; + } if (StoreInst* S = dyn_cast(curr)) { // We know this must be an instruction, because constant gep's would