Teach LoopSimplify how to merge multiple loop exits into a single exit,
authorDan Gohman <gohman@apple.com>
Sat, 27 Jun 2009 21:30:38 +0000 (21:30 +0000)
committerDan Gohman <gohman@apple.com>
Sat, 27 Jun 2009 21:30:38 +0000 (21:30 +0000)
commit4b35f83b91a1a313f0730c600e5178aaf7df98d6
tree50006e0a70949304f64ee1395d602224e8338078
parentcfb32203bceb0638db976fea5ce906b2a1010bac
Teach LoopSimplify how to merge multiple loop exits into a single exit,
when one of them can be converted to a trivial icmp and conditional
branch.

This addresses what is essentially a phase ordering problem.
SimplifyCFG knows how to do this transformation, but it doesn't do so
if the primary block has any instructions in it other than an icmp and
a branch. In the given testcase, the block contains other instructions,
however they are loop-invariant and can be hoisted. SimplifyCFG doesn't
have LoopInfo though, so it can't hoist them. And, it's important that
the blocks be merged before LoopRotation, as it doesn't support
multiple-exit loops.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74396 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Transforms/Utils/Local.h
lib/Transforms/Utils/LoopSimplify.cpp
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/LoopSimplify/merge-exits.ll [new file with mode: 0644]