From: Fangrui Song Date: Sun, 14 Apr 2019 07:20:03 +0000 (+0000) Subject: [Mem2Reg] Simplify and micro optimize X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=adb4c21c6de78325bb243e104ed5892d0e190501;p=llvm [Mem2Reg] Simplify and micro optimize * Rearrange continu/break * BBNumbers.lookup(A) -> BBNumbers.find(A)->second BBNumbers has been computed, thus we can assume the value exists in the predicate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358351 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index bdf1c209d59..4cdef6def01 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -606,8 +606,8 @@ void PromoteMem2Reg::run() { // dead phi nodes. // Unique the set of defining blocks for efficient lookup. - SmallPtrSet DefBlocks; - DefBlocks.insert(Info.DefiningBlocks.begin(), Info.DefiningBlocks.end()); + SmallPtrSet DefBlocks(Info.DefiningBlocks.begin(), + Info.DefiningBlocks.end()); // Determine which blocks the value is live in. These are blocks which lead // to uses. @@ -622,10 +622,9 @@ void PromoteMem2Reg::run() { IDF.setDefiningBlocks(DefBlocks); SmallVector PHIBlocks; IDF.calculate(PHIBlocks); - if (PHIBlocks.size() > 1) - llvm::sort(PHIBlocks, [this](BasicBlock *A, BasicBlock *B) { - return BBNumbers.lookup(A) < BBNumbers.lookup(B); - }); + llvm::sort(PHIBlocks, [this](BasicBlock *A, BasicBlock *B) { + return BBNumbers.find(A)->second < BBNumbers.find(B)->second; + }); unsigned CurrentVersion = 0; for (BasicBlock *BB : PHIBlocks) @@ -737,7 +736,7 @@ void PromoteMem2Reg::run() { // basic blocks. Start by sorting the incoming predecessors for efficient // access. auto CompareBBNumbers = [this](BasicBlock *A, BasicBlock *B) { - return BBNumbers.lookup(A) < BBNumbers.lookup(B); + return BBNumbers.find(A)->second < BBNumbers.find(B)->second; }; llvm::sort(Preds, CompareBBNumbers); @@ -810,14 +809,11 @@ void PromoteMem2Reg::ComputeLiveInBlocks( break; } - if (LoadInst *LI = dyn_cast(I)) { - if (LI->getOperand(0) != AI) - continue; - + if (LoadInst *LI = dyn_cast(I)) // Okay, we found a load before a store to the alloca. It is actually // live into this block. - break; - } + if (LI->getOperand(0) == AI) + break; } }