llvm.org GIT mirror llvm / 4734fe1
Hoist out some work done inside a loop doing a linear scan over all instructions in a block. GetUnderlyingObject is more expensive than it looks as it can, for instance, call SimplifyInstruction. This might have some behavioural changes in odd corner cases, but only because of some strange artefacts of the original implementation. If you were relying on those, we can fix that by replacing this with a smarter algorithm. Change passes the existing tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166754 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 8 years ago
1 changed file(s) with 17 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1212 //===----------------------------------------------------------------------===//
1313
1414 #define DEBUG_TYPE "lazy-value-info"
15 #include "llvm/Analysis/AliasAnalysis.h"
1516 #include "llvm/Analysis/LazyValueInfo.h"
1617 #include "llvm/Analysis/ValueTracking.h"
1718 #include "llvm/Constants.h"
293294 //===----------------------------------------------------------------------===//
294295
295296 namespace {
296 /// LVIValueHandle - A callback value handle update the cache when
297 /// LVIValueHandle - A callback value handle updates the cache when
297298 /// values are erased.
298299 class LazyValueInfoCache;
299300 struct LVIValueHandle : public CallbackVH {
556557 static bool InstructionDereferencesPointer(Instruction *I, Value *Ptr) {
557558 if (LoadInst *L = dyn_cast(I)) {
558559 return L->getPointerAddressSpace() == 0 &&
559 GetUnderlyingObject(L->getPointerOperand()) ==
560 GetUnderlyingObject(Ptr);
560 GetUnderlyingObject(L->getPointerOperand()) == Ptr;
561561 }
562562 if (StoreInst *S = dyn_cast(I)) {
563563 return S->getPointerAddressSpace() == 0 &&
564 GetUnderlyingObject(S->getPointerOperand()) ==
565 GetUnderlyingObject(Ptr);
564 GetUnderlyingObject(S->getPointerOperand()) == Ptr;
566565 }
567566 if (MemIntrinsic *MI = dyn_cast(I)) {
568567 if (MI->isVolatile()) return false;
572571 if (!Len || Len->isZero()) return false;
573572
574573 if (MI->getDestAddressSpace() == 0)
575 if (MI->getRawDest() == Ptr || MI->getDest() == Ptr)
574 if (GetUnderlyingObject(MI->getRawDest()) == Ptr)
576575 return true;
577576 if (MemTransferInst *MTI = dyn_cast(MI))
578577 if (MTI->getSourceAddressSpace() == 0)
579 if (MTI->getRawSource() == Ptr || MTI->getSource() == Ptr)
578 if (GetUnderlyingObject(MTI->getRawSource()) == Ptr)
580579 return true;
581580 }
582581 return false;
590589 // then we know that the pointer can't be NULL.
591590 bool NotNull = false;
592591 if (Val->getType()->isPointerTy()) {
593 if (isa(Val)) {
592 if (isKnownNonNull(Val)) {
594593 NotNull = true;
595594 } else {
596 for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();BI != BE;++BI){
597 if (InstructionDereferencesPointer(BI, Val)) {
598 NotNull = true;
599 break;
595 Value *UnderlyingVal = GetUnderlyingObject(Val);
596 // If 'GetUnderlyingObject' didn't converge, skip it. It won't converge
597 // inside InstructionDereferencesPointer either.
598 if (UnderlyingVal == GetUnderlyingObject(UnderlyingVal, NULL, 1)) {
599 for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
600 BI != BE; ++BI) {
601 if (InstructionDereferencesPointer(BI, UnderlyingVal)) {
602 NotNull = true;
603 break;
604 }
600605 }
601606 }
602607 }