Index: llvm/trunk/include/llvm/IR/Instruction.h =================================================================== --- llvm/trunk/include/llvm/IR/Instruction.h +++ llvm/trunk/include/llvm/IR/Instruction.h @@ -582,6 +582,10 @@ } } + /// Return true if the instruction is a llvm.lifetime.start or + /// llvm.lifetime.end marker. + bool isLifetimeStartOrEnd() const; + /// Return a pointer to the next non-debug instruction in the same basic /// block as 'this', or nullptr if no such instruction exists. const Instruction *getNextNonDebugInstruction() const; Index: llvm/trunk/lib/Analysis/StackSafetyAnalysis.cpp =================================================================== --- llvm/trunk/lib/Analysis/StackSafetyAnalysis.cpp +++ llvm/trunk/lib/Analysis/StackSafetyAnalysis.cpp @@ -323,11 +323,8 @@ case Instruction::Invoke: { ImmutableCallSite CS(I); - if (const IntrinsicInst *II = dyn_cast(I)) { - if (II->getIntrinsicID() == Intrinsic::lifetime_start || - II->getIntrinsicID() == Intrinsic::lifetime_end) - break; - } + if (I->isLifetimeStartOrEnd()) + break; if (const MemIntrinsic *MI = dyn_cast(I)) { US.updateRange(getMemIntrinsicAccessRange(MI, UI, Ptr)); Index: llvm/trunk/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/trunk/lib/Analysis/ValueTracking.cpp +++ llvm/trunk/lib/Analysis/ValueTracking.cpp @@ -3822,8 +3822,7 @@ const IntrinsicInst *II = dyn_cast(U); if (!II) return false; - if (II->getIntrinsicID() != Intrinsic::lifetime_start && - II->getIntrinsicID() != Intrinsic::lifetime_end) + if (!II->isLifetimeStartOrEnd()) return false; } return true; Index: llvm/trunk/lib/CodeGen/SafeStack.cpp =================================================================== --- llvm/trunk/lib/CodeGen/SafeStack.cpp +++ llvm/trunk/lib/CodeGen/SafeStack.cpp @@ -324,11 +324,8 @@ case Instruction::Invoke: { ImmutableCallSite CS(I); - if (const IntrinsicInst *II = dyn_cast(I)) { - if (II->getIntrinsicID() == Intrinsic::lifetime_start || - II->getIntrinsicID() == Intrinsic::lifetime_end) - continue; - } + if (I->isLifetimeStartOrEnd()) + continue; if (const MemIntrinsic *MI = dyn_cast(I)) { if (!IsMemIntrinsicSafe(MI, UI, AllocaPtr, AllocaSize)) { Index: llvm/trunk/lib/CodeGen/SafeStackColoring.cpp =================================================================== --- llvm/trunk/lib/CodeGen/SafeStackColoring.cpp +++ llvm/trunk/lib/CodeGen/SafeStackColoring.cpp @@ -46,11 +46,10 @@ } bool StackColoring::readMarker(Instruction *I, bool *IsStart) { - auto *II = dyn_cast(I); - if (!II || (II->getIntrinsicID() != Intrinsic::lifetime_start && - II->getIntrinsicID() != Intrinsic::lifetime_end)) + if (!I->isLifetimeStartOrEnd()) return false; + auto *II = cast(I); *IsStart = II->getIntrinsicID() == Intrinsic::lifetime_start; return true; } Index: llvm/trunk/lib/CodeGen/StackProtector.cpp =================================================================== --- llvm/trunk/lib/CodeGen/StackProtector.cpp +++ llvm/trunk/lib/CodeGen/StackProtector.cpp @@ -157,14 +157,6 @@ return NeedsProtector; } -static bool isLifetimeInst(const Instruction *I) { - if (const auto Intrinsic = dyn_cast(I)) { - const auto Id = Intrinsic->getIntrinsicID(); - return Id == Intrinsic::lifetime_start || Id == Intrinsic::lifetime_end; - } - return false; -} - bool StackProtector::HasAddressTaken(const Instruction *AI) { for (const User *U : AI->users()) { if (const StoreInst *SI = dyn_cast(U)) { @@ -175,7 +167,7 @@ return true; } else if (const CallInst *CI = dyn_cast(U)) { // Ignore intrinsics that are not calls. TODO: Use isLoweredToCall(). - if (!isa(CI) && !isLifetimeInst(CI)) + if (!isa(CI) && !CI->isLifetimeStartOrEnd()) return true; } else if (isa(U)) { return true; Index: llvm/trunk/lib/IR/BasicBlock.cpp =================================================================== --- llvm/trunk/lib/IR/BasicBlock.cpp +++ llvm/trunk/lib/IR/BasicBlock.cpp @@ -206,10 +206,8 @@ if (isa(I) || isa(I)) continue; - if (auto *II = dyn_cast(&I)) - if (II->getIntrinsicID() == Intrinsic::lifetime_start || - II->getIntrinsicID() == Intrinsic::lifetime_end) - continue; + if (I.isLifetimeStartOrEnd()) + continue; return &I; } Index: llvm/trunk/lib/IR/Instruction.cpp =================================================================== --- llvm/trunk/lib/IR/Instruction.cpp +++ llvm/trunk/lib/IR/Instruction.cpp @@ -598,6 +598,14 @@ !this->isTerminator(); } +bool Instruction::isLifetimeStartOrEnd() const { + auto II = dyn_cast(this); + if (!II) + return false; + Intrinsic::ID ID = II->getIntrinsicID(); + return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end; +} + const Instruction *Instruction::getNextNonDebugInstruction() const { for (const Instruction *I = getNextNode(); I; I = I->getNextNode()) if (!isa(I)) Index: llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp =================================================================== --- llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp +++ llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp @@ -851,12 +851,8 @@ break; } - IntrinsicInst *IntrInst = dyn_cast(&I); - if (IntrInst) { - if (IntrInst->getIntrinsicID() == Intrinsic::lifetime_start || - IntrInst->getIntrinsicID() == Intrinsic::lifetime_end) - continue; - } + if (I.isLifetimeStartOrEnd()) + continue; if (CallInst *CI = dyn_cast(&I)) { InlineCost += getCallsiteCost(CallSite(CI), DL); Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -116,13 +116,10 @@ } // Lifetime intrinsics can be handled by the caller. - if (IntrinsicInst *II = dyn_cast(I)) { - if (II->getIntrinsicID() == Intrinsic::lifetime_start || - II->getIntrinsicID() == Intrinsic::lifetime_end) { - assert(II->use_empty() && "Lifetime markers have no result to use!"); - ToDelete.push_back(II); - continue; - } + if (I->isLifetimeStartOrEnd()) { + assert(I->use_empty() && "Lifetime markers have no result to use!"); + ToDelete.push_back(I); + continue; } // If this is isn't our memcpy/memmove, reject it as something we can't Index: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1005,7 +1005,7 @@ if (ID == Intrinsic::localescape) LocalEscapeCall = &II; if (!ASan.UseAfterScope) return; - if (ID != Intrinsic::lifetime_start && ID != Intrinsic::lifetime_end) + if (!II.isLifetimeStartOrEnd()) return; // Found lifetime intrinsic, add ASan instrumentation if necessary. ConstantInt *Size = dyn_cast(II.getArgOperand(0)); Index: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -919,8 +919,7 @@ continue; } if (const IntrinsicInst *IT = dyn_cast(U)) - if (IT->getIntrinsicID() == Intrinsic::lifetime_start || - IT->getIntrinsicID() == Intrinsic::lifetime_end) + if (IT->isLifetimeStartOrEnd()) continue; if (U != C && U != cpy) Index: llvm/trunk/lib/Transforms/Scalar/SROA.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/SROA.cpp +++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp @@ -913,8 +913,7 @@ if (!IsOffsetKnown) return PI.setAborted(&II); - if (II.getIntrinsicID() == Intrinsic::lifetime_start || - II.getIntrinsicID() == Intrinsic::lifetime_end) { + if (II.isLifetimeStartOrEnd()) { ConstantInt *Length = cast(II.getArgOperand(0)); uint64_t Size = std::min(AllocSize - Offset.getLimitedValue(), Length->getLimitedValue()); @@ -1807,8 +1806,7 @@ if (!S.isSplittable()) return false; // Skip any unsplittable intrinsics. } else if (IntrinsicInst *II = dyn_cast(U->getUser())) { - if (II->getIntrinsicID() != Intrinsic::lifetime_start && - II->getIntrinsicID() != Intrinsic::lifetime_end) + if (!II->isLifetimeStartOrEnd()) return false; } else if (U->get()->getType()->getPointerElementType()->isStructTy()) { // Disable vector promotion when there are loads or stores of an FCA. @@ -2029,8 +2027,7 @@ if (!S.isSplittable()) return false; // Skip any unsplittable intrinsics. } else if (IntrinsicInst *II = dyn_cast(U->getUser())) { - if (II->getIntrinsicID() != Intrinsic::lifetime_start && - II->getIntrinsicID() != Intrinsic::lifetime_end) + if (!II->isLifetimeStartOrEnd()) return false; } else { return false; @@ -3013,8 +3010,7 @@ } bool visitIntrinsicInst(IntrinsicInst &II) { - assert(II.getIntrinsicID() == Intrinsic::lifetime_start || - II.getIntrinsicID() == Intrinsic::lifetime_end); + assert(II.isLifetimeStartOrEnd()); LLVM_DEBUG(dbgs() << " original: " << II << "\n"); assert(II.getArgOperand(1) == OldPtr); Index: llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp +++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp @@ -332,8 +332,7 @@ default: { IntrinsicInst *IntrInst = dyn_cast(&II); if (IntrInst) { - if (IntrInst->getIntrinsicID() == Intrinsic::lifetime_start || - IntrInst->getIntrinsicID() == Intrinsic::lifetime_end) + if (IntrInst->isLifetimeStartOrEnd()) break; return false; } Index: llvm/trunk/lib/Transforms/Utils/Evaluator.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/Evaluator.cpp +++ llvm/trunk/lib/Transforms/Utils/Evaluator.cpp @@ -483,8 +483,7 @@ } } - if (II->getIntrinsicID() == Intrinsic::lifetime_start || - II->getIntrinsicID() == Intrinsic::lifetime_end) { + if (II->isLifetimeStartOrEnd()) { LLVM_DEBUG(dbgs() << "Ignoring lifetime intrinsic.\n"); ++CurInst; continue; Index: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp +++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp @@ -1320,16 +1320,10 @@ // Check whether this Value is used by a lifetime intrinsic. static bool isUsedByLifetimeMarker(Value *V) { - for (User *U : V->users()) { - if (IntrinsicInst *II = dyn_cast(U)) { - switch (II->getIntrinsicID()) { - default: break; - case Intrinsic::lifetime_start: - case Intrinsic::lifetime_end: + for (User *U : V->users()) + if (IntrinsicInst *II = dyn_cast(U)) + if (II->isLifetimeStartOrEnd()) return true; - } - } - } return false; } Index: llvm/trunk/lib/Transforms/Utils/Local.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/Local.cpp +++ llvm/trunk/lib/Transforms/Utils/Local.cpp @@ -393,8 +393,7 @@ return true; // Lifetime intrinsics are dead when their right-hand is undef. - if (II->getIntrinsicID() == Intrinsic::lifetime_start || - II->getIntrinsicID() == Intrinsic::lifetime_end) + if (II->isLifetimeStartOrEnd()) return isa(II->getArgOperand(1)); // Assumptions are dead if their condition is trivially true. Guards on Index: llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -82,8 +82,7 @@ if (SI->isVolatile()) return false; } else if (const IntrinsicInst *II = dyn_cast(U)) { - if (II->getIntrinsicID() != Intrinsic::lifetime_start && - II->getIntrinsicID() != Intrinsic::lifetime_end) + if (!II->isLifetimeStartOrEnd()) return false; } else if (const BitCastInst *BCI = dyn_cast(U)) { if (BCI->getType() != Type::getInt8PtrTy(U->getContext(), AS))