From: Larisse Voufo Date: Sat, 12 Sep 2015 01:41:55 +0000 (+0000) Subject: Clean up: Refactoring the hardcoded value of 6 for FindAvailableLoadedValue()'s param... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f57162b6e769e7f3fcdec47eb3f38041599ffeb3;p=platform%2Fupstream%2Fllvm.git Clean up: Refactoring the hardcoded value of 6 for FindAvailableLoadedValue()'s parameter MaxInstsToScan. llvm-svn: 247497 --- diff --git a/llvm/include/llvm/Analysis/Loads.h b/llvm/include/llvm/Analysis/Loads.h index 698b665..3107a76 100644 --- a/llvm/include/llvm/Analysis/Loads.h +++ b/llvm/include/llvm/Analysis/Loads.h @@ -29,15 +29,28 @@ class MDNode; bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom, unsigned Align); +/// DEF_MAX_INSTS_TO_SCAN - the default number of maximum instructions +/// to scan in the block, used by FindAvailableLoadedValue(). +/// FindAvailableLoadedValue() was introduced in r60148, to improve jump +/// threading in part by eliminating partially redundant loads. +/// At that point, the value of MaxInstsToScan was already set to '6' +/// without documented explanation. +/// FIXME: Ask r60148 author for details, and complete this documentation. +/// NOTE: As of now, every use of FindAvailableLoadedValue() uses this default +/// value of '6'. +#ifndef DEF_MAX_INSTS_TO_SCAN +#define DEF_MAX_INSTS_TO_SCAN 6 +#endif + /// FindAvailableLoadedValue - Scan the ScanBB block backwards (starting at /// the instruction before ScanFrom) checking to see if we have the value at /// the memory address *Ptr locally available within a small number of /// instructions. If the value is available, return it. /// -/// If not, return the iterator for the last validated instruction that the +/// If not, return the iterator for the last validated instruction that the /// value would be live through. If we scanned the entire block and didn't /// find something that invalidates *Ptr or provides it, ScanFrom would be -/// left at begin() and this returns null. ScanFrom could also be left +/// left at begin() and this returns null. ScanFrom could also be left /// /// MaxInstsToScan specifies the maximum instructions to scan in the block. /// If it is set to 0, it will scan the whole block. You can also optionally @@ -48,7 +61,7 @@ bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom, /// is found, it is left unmodified. Value *FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, - unsigned MaxInstsToScan = 6, + unsigned MaxInstsToScan = DEF_MAX_INSTS_TO_SCAN, AliasAnalysis *AA = nullptr, AAMDNodes *AATags = nullptr); diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp index 0f5599e..4928e45 100644 --- a/llvm/lib/Analysis/Lint.cpp +++ b/llvm/lib/Analysis/Lint.cpp @@ -829,8 +829,9 @@ Value *Lint::findValueImpl(Value *V, bool OffsetOk, for (;;) { if (!VisitedBlocks.insert(BB).second) break; - if (Value *U = FindAvailableLoadedValue(L->getPointerOperand(), - BB, BBI, 6, AA)) + if (Value *U = + FindAvailableLoadedValue(L->getPointerOperand(), + BB, BBI, DEF_MAX_INSTS_TO_SCAN, AA)) return findValueImpl(U, OffsetOk, Visited); if (BBI != BB->begin()) break; BB = BB->getUniquePredecessor(); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 3c70f44..32d3f80 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -750,8 +750,9 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { // separated by a few arithmetic operations. BasicBlock::iterator BBI = &LI; AAMDNodes AATags; - if (Value *AvailableVal = FindAvailableLoadedValue(Op, LI.getParent(), BBI, - 6, AA, &AATags)) { + if (Value *AvailableVal = + FindAvailableLoadedValue(Op, LI.getParent(), BBI, + DEF_MAX_INSTS_TO_SCAN, AA, &AATags)) { if (LoadInst *NLI = dyn_cast(AvailableVal)) { unsigned KnownIDs[] = { LLVMContext::MD_tbaa, @@ -822,7 +823,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { } // load (select (cond, null, P)) -> load P - if (isa(SI->getOperand(1)) && + if (isa(SI->getOperand(1)) && LI.getPointerAddressSpace() == 0) { LI.setOperand(0, SI->getOperand(2)); return &LI; diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index f713768..d3b9a34 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -769,7 +769,7 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) { // If we're branching on a conditional, LVI might be able to determine // it's value at the branch instruction. We only handle comparisons // against a constant at this time. - // TODO: This should be extended to handle switches as well. + // TODO: This should be extended to handle switches as well. BranchInst *CondBr = dyn_cast(BB->getTerminator()); Constant *CondConst = dyn_cast(CondCmp->getOperand(1)); if (CondBr && CondConst && CondBr->isConditional()) { @@ -877,7 +877,7 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) { BasicBlock::iterator BBIt = LI; if (Value *AvailableVal = - FindAvailableLoadedValue(LoadedPtr, LoadBB, BBIt, 6)) { + FindAvailableLoadedValue(LoadedPtr, LoadBB, BBIt)) { // If the value if the load is locally available within the block, just use // it. This frequently occurs for reg2mem'd allocas. //cerr << "LOAD ELIMINATED:\n" << *BBIt << *LI << "\n"; @@ -922,7 +922,8 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) { // Scan the predecessor to see if the value is available in the pred. BBIt = PredBB->end(); AAMDNodes ThisAATags; - Value *PredAvailable = FindAvailableLoadedValue(LoadedPtr, PredBB, BBIt, 6, + Value *PredAvailable = FindAvailableLoadedValue(LoadedPtr, PredBB, BBIt, + DEF_MAX_INSTS_TO_SCAN, nullptr, &ThisAATags); if (!PredAvailable) { OneUnavailablePred = PredBB;