diff options
author | Hyojin Sung <hsung@us.ibm.com> | 2016-03-28 17:22:25 +0000 |
---|---|---|
committer | Hyojin Sung <hsung@us.ibm.com> | 2016-03-28 17:22:25 +0000 |
commit | 0ada5b0d14ec6111da461ddec9f10c4fb5f595d1 (patch) | |
tree | 64291e93a94ffea888a903e87a4c9f19ed5ad654 /llvm/include | |
parent | 7d564ba19e5b363023abf19a74e9dfcb278084d9 (diff) | |
download | bcm5719-llvm-0ada5b0d14ec6111da461ddec9f10c4fb5f595d1.tar.gz bcm5719-llvm-0ada5b0d14ec6111da461ddec9f10c4fb5f595d1.zip |
[SimlifyCFG] Prevent passes from destroying canonical loop structure, especially for nested loops
When eliminating or merging almost empty basic blocks, the existence of non-trivial PHI nodes
is currently used to recognize potential loops of which the block is the header and keep the block.
However, the current algorithm fails if the loops' exit condition is evaluated only with volatile
values hence no PHI nodes in the header. Especially when such a loop is an outer loop of a nested
loop, the loop is collapsed into a single loop which prevent later optimizations from being
applied (e.g., transforming nested loops into simplified forms and loop vectorization).
The patch augments the existing PHI node-based check by adding a pre-test if the BB actually
belongs to a set of loop headers and not eliminating it if yes.
llvm-svn: 264596
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/Transforms/Utils/Local.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index df8082ec749..dd47843e2b7 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -21,6 +21,7 @@ #include "llvm/IR/GetElementPtrTypeIterator.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Operator.h" +#include "llvm/ADT/SmallPtrSet.h" namespace llvm { @@ -124,13 +125,16 @@ bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB); /// values, but instcombine orders them so it usually won't matter. bool EliminateDuplicatePHINodes(BasicBlock *BB); -/// This function is used to do simplification of a CFG. For example, it -/// adjusts branches to branches to eliminate the extra hop, it eliminates -/// unreachable basic blocks, and does other "peephole" optimization of the CFG. -/// It returns true if a modification was made, possibly deleting the basic -/// block that was pointed to. +/// This function is used to do simplification of a CFG. For +/// example, it adjusts branches to branches to eliminate the extra hop, it +/// eliminates unreachable basic blocks, and does other "peephole" optimization +/// of the CFG. It returns true if a modification was made, possibly deleting +/// the basic block that was pointed to. LoopHeaders is an optional input +/// parameter, providing the set of loop header that SimplifyCFG should not +/// eliminate. bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, - unsigned BonusInstThreshold, AssumptionCache *AC = nullptr); + unsigned BonusInstThreshold, AssumptionCache *AC = nullptr, + SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr); /// This function is used to flatten a CFG. For example, it uses parallel-and /// and parallel-or mode to collapse if-conditions and merge if-regions with |