diff options
author | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2016-03-01 14:39:55 +0000 |
---|---|---|
committer | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2016-03-01 14:39:55 +0000 |
commit | 8aef99aa86b251bf33a83ac24c13f4df0c189067 (patch) | |
tree | 36e91235b4014fb71bfe62b470460175c805e624 /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | |
parent | 2cc9d4795fbc1392fdaf31174376b259524f4a28 (diff) | |
download | llvm-8aef99aa86b251bf33a83ac24c13f4df0c189067.zip llvm-8aef99aa86b251bf33a83ac24c13f4df0c189067.tar.gz llvm-8aef99aa86b251bf33a83ac24c13f4df0c189067.tar.bz2 |
calculate builtin_object_size if argument is a removable pointer
This patch fixes calculating correct value for builtin_object_size function
when pointer is used only in builtin_object_size function call and never
after that.
Patch by Strahinja Petrovic.
Differential Revision: http://reviews.llvm.org/D17337
llvm-svn: 262337
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 1b95e93..de4dfb5 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1942,6 +1942,25 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) { SmallVector<WeakVH, 64> Users; if (isAllocSiteRemovable(&MI, Users, TLI)) { for (unsigned i = 0, e = Users.size(); i != e; ++i) { + // Lowering all @llvm.objectsize calls first because they may + // use a bitcast/GEP of the alloca we are removing. + Instruction *I = cast_or_null<Instruction>(&*Users[i]); + if (!I) continue; + + if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) { + if (II->getIntrinsicID() == Intrinsic::objectsize) { + uint64_t Size; + if (!getObjectSize(II->getArgOperand(0), Size, DL, TLI)) { + ConstantInt *CI = cast<ConstantInt>(II->getArgOperand(1)); + Size = CI->isZero() ? -1ULL : 0; + } + replaceInstUsesWith(*I, ConstantInt::get(I->getType(), Size)); + eraseInstFromFunction(*I); + Users[i] = nullptr; // Skip examining in the next loop. + } + } + } + for (unsigned i = 0, e = Users.size(); i != e; ++i) { Instruction *I = cast_or_null<Instruction>(&*Users[i]); if (!I) continue; @@ -1951,12 +1970,6 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) { C->isFalseWhenEqual())); } else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) { replaceInstUsesWith(*I, UndefValue::get(I->getType())); - } else if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) { - if (II->getIntrinsicID() == Intrinsic::objectsize) { - ConstantInt *CI = cast<ConstantInt>(II->getArgOperand(1)); - uint64_t DontKnow = CI->isZero() ? -1ULL : 0; - replaceInstUsesWith(*I, ConstantInt::get(I->getType(), DontKnow)); - } } eraseInstFromFunction(*I); } |