summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-18 04:25:21 +0000
committerChris Lattner <sabre@nondot.org>2011-02-18 04:25:21 +0000
commit4a14fbc50c68ba3cc71134ede94e37a8ff688db0 (patch)
tree434902a1e7321e29f82713b88422c788ab260ecb
parentc4ef61af9a6e0f9c7dd49cef694e8111ab454049 (diff)
downloadbcm5719-llvm-4a14fbc50c68ba3cc71134ede94e37a8ff688db0.tar.gz
bcm5719-llvm-4a14fbc50c68ba3cc71134ede94e37a8ff688db0.zip
Don't unroll loops whose header block's address is taken.
This is part of a futile attempt to not "break" bizzaro code like this: l1: printf("l1: %p\n", &&l1); ++x; if( x < 3 ) goto l1; Previously we'd fold &&l1 to 1, which is fine per our semantics but not helpful to the user. llvm-svn: 125827
-rw-r--r--llvm/lib/Transforms/Utils/LoopUnroll.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index dd8c154fdd7..7da7271e642 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -96,7 +96,7 @@ static BasicBlock *FoldBlockIntoPredecessor(BasicBlock *BB, LoopInfo* LI) {
}
/// Unroll the given loop by Count. The loop must be in LCSSA form. Returns true
-/// if unrolling was succesful, or false if the loop was unmodified. Unrolling
+/// if unrolling was successful, or false if the loop was unmodified. Unrolling
/// can only fail when the loop's latch block is not terminated by a conditional
/// branch instruction. However, if the trip count (and multiple) are not known,
/// loop unrolling will mostly produce more code that is no faster.
@@ -105,7 +105,8 @@ static BasicBlock *FoldBlockIntoPredecessor(BasicBlock *BB, LoopInfo* LI) {
///
/// If a LoopPassManager is passed in, and the loop is fully removed, it will be
/// removed from the LoopPassManager as well. LPM can also be NULL.
-bool llvm::UnrollLoop(Loop *L, unsigned Count, LoopInfo* LI, LPPassManager* LPM) {
+bool llvm::UnrollLoop(Loop *L, unsigned Count,
+ LoopInfo *LI, LPPassManager *LPM) {
BasicBlock *Preheader = L->getLoopPreheader();
if (!Preheader) {
DEBUG(dbgs() << " Can't unroll; loop preheader-insertion failed.\n");
@@ -127,6 +128,13 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, LoopInfo* LI, LPPassManager* LPM)
" Can't unroll; loop not terminated by a conditional branch.\n");
return false;
}
+
+ if (Header->hasAddressTaken()) {
+ // The loop-rotate pass can be helpful to avoid this in many cases.
+ DEBUG(dbgs() <<
+ " Won't unroll loop: address of header block is taken.\n");
+ return false;
+ }
// Notify ScalarEvolution that the loop will be substantially changed,
// if not outright eliminated.
OpenPOWER on IntegriCloud