[LoopUnswitch] Improve loop unswitch pass to find trivial unswitch conditions more...
authorChen Li <meloli87@gmail.com>
Sat, 25 Jul 2015 03:21:06 +0000 (03:21 +0000)
committerChen Li <meloli87@gmail.com>
Sat, 25 Jul 2015 03:21:06 +0000 (03:21 +0000)
commit7b0238cdc135ca38ff04ec44c06dc59728ee3444
tree87ece1cbeb1e3c112b56bfb90e07394c621a5d3c
parente928ceb9e61b9cee0109ec5f37ea05176740d4ef
[LoopUnswitch] Improve loop unswitch pass to find trivial unswitch conditions more effectively

Summary:
This patch improves trivial loop unswitch.

The current trivial loop unswitch only checks if loop header's terminator contains a trivial unswitch condition. But if the loop header only has one reachable successor (due to intentionally or unintentionally missed code simplification), we should consider the successor as part of the loop header. Therefore, instead of stopping at loop header's terminator, we should keep traversing its successors within loop until reach a *real* conditional branch or switch (whose condition can not be constant folded). This change will enable a single -loop-unswitch pass to unswitch multiple trivial conditions (unswitch one trivial condition could open opportunity to unswitch another one in the same loop), while the old implementation can unswitch only one per pass.

Reviewers: reames, broune

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D11481

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243203 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/LoopUnswitch.cpp
test/Transforms/LoopUnswitch/infinite-loop.ll
test/Transforms/LoopUnswitch/trivial-unswitch.ll [new file with mode: 0644]