diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2016-10-15 13:15:05 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2016-10-15 13:15:05 +0000 |
commit | d8b079708da672c99529b213cb3be7fea6a86830 (patch) | |
tree | e6f790f209f19efd92346bf7c076677bcb89d525 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 4b5e24df9a8559dec580c01439df6082e15ad277 (diff) | |
download | bcm5719-llvm-d8b079708da672c99529b213cb3be7fea6a86830.tar.gz bcm5719-llvm-d8b079708da672c99529b213cb3be7fea6a86830.zip |
[SimplifyCFG] Use the error checking provided by getPrevNode.
BasicBlock::size is O(insts), making this loop O(blocks*insts), which
can be really slow on generated code. getPrevNode already checks if
we're at the beginning of the block and returns nullptr if so, just use
that instead. No functionality change intended.
llvm-svn: 284303
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index a45a0c75b46..21bb87b84fc 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1584,12 +1584,15 @@ namespace { Fail = false; Insts.clear(); for (auto *BB : Blocks) { - if (BB->size() <= 1) { - // Block wasn't big enough - Fail = true; - return; + if (Instruction *Terminator = BB->getTerminator()) { + if (Instruction *LastNonTerminator = Terminator->getPrevNode()) { + Insts.push_back(LastNonTerminator); + continue; + } } - Insts.push_back(BB->getTerminator()->getPrevNode()); + // Block wasn't big enough. + Fail = true; + return; } } @@ -1601,11 +1604,12 @@ namespace { if (Fail) return; for (auto *&Inst : Insts) { - if (Inst == &Inst->getParent()->front()) { + Inst = Inst->getPrevNode(); + // Already at beginning of block. + if (!Inst) { Fail = true; return; } - Inst = Inst->getPrevNode(); } } |