aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-07-14 01:37:59 +0000
committerDan Gohman <gohman@apple.com>2009-07-14 01:37:59 +0000
commitc05b35881e127ec5cfc384a39d3b9db00aeda12c (patch)
tree4f3d6d05529e7ec08a8a52ce1174bda6cad1f98a /lib
parent884b11ba772af1125d723c58bc14c22913bc80d5 (diff)
downloadexternal_llvm-c05b35881e127ec5cfc384a39d3b9db00aeda12c.zip
external_llvm-c05b35881e127ec5cfc384a39d3b9db00aeda12c.tar.gz
external_llvm-c05b35881e127ec5cfc384a39d3b9db00aeda12c.tar.bz2
Update LoopSimplify and LoopUnswitch to use the new makeLoopInvariant
function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75584 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/LoopUnswitch.cpp7
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp23
2 files changed, 15 insertions, 15 deletions
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp
index 0a3659c..f5061b5 100644
--- a/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -168,9 +168,14 @@ static Value *FindLIVLoopCondition(Value *Cond, Loop *L, bool &Changed) {
if (isa<Constant>(Cond)) return 0;
// TODO: Handle: br (VARIANT|INVARIANT).
- // TODO: Hoist simple expressions out of loops.
if (L->isLoopInvariant(Cond)) return Cond;
+ // Hoist simple values out.
+ if (L->makeLoopInvariant(Cond)) {
+ Changed = true;
+ return Cond;
+ }
+
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Cond))
if (BO->getOpcode() == Instruction::And ||
BO->getOpcode() == Instruction::Or) {
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index e80ef02..cfdfcb0 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -91,7 +91,7 @@ namespace {
private:
bool ProcessLoop(Loop *L);
BasicBlock *RewriteLoopExitBlock(Loop *L, BasicBlock *Exit);
- void InsertPreheaderForLoop(Loop *L);
+ BasicBlock *InsertPreheaderForLoop(Loop *L);
Loop *SeparateNestedLoop(Loop *L);
void InsertUniqueBackedgeBlock(Loop *L);
void PlaceSplitBlockCarefully(BasicBlock *NewBB,
@@ -193,8 +193,9 @@ ReprocessLoop:
"Header isn't first block in loop?");
// Does the loop already have a preheader? If so, don't insert one.
- if (L->getLoopPreheader() == 0) {
- InsertPreheaderForLoop(L);
+ BasicBlock *Preheader = L->getLoopPreheader();
+ if (!Preheader) {
+ Preheader = InsertPreheaderForLoop(L);
NumInserted++;
Changed = true;
}
@@ -287,19 +288,11 @@ ReprocessLoop:
Instruction *Inst = I++;
if (Inst == CI)
continue;
- if (Inst->isTrapping()) {
+ if (!L->makeLoopInvariant(Inst, Preheader->getTerminator())) {
AllInvariant = false;
+ Changed = true;
break;
}
- for (unsigned j = 0, f = Inst->getNumOperands(); j != f; ++j)
- if (!L->isLoopInvariant(Inst->getOperand(j))) {
- AllInvariant = false;
- break;
- }
- if (!AllInvariant)
- break;
- // Hoist.
- Inst->moveBefore(L->getLoopPreheader()->getTerminator());
}
if (!AllInvariant) continue;
@@ -340,7 +333,7 @@ ReprocessLoop:
/// preheader, this method is called to insert one. This method has two phases:
/// preheader insertion and analysis updating.
///
-void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
+BasicBlock *LoopSimplify::InsertPreheaderForLoop(Loop *L) {
BasicBlock *Header = L->getHeader();
// Compute the set of predecessors of the loop that are not in the loop.
@@ -367,6 +360,8 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
// Make sure that NewBB is put someplace intelligent, which doesn't mess up
// code layout too horribly.
PlaceSplitBlockCarefully(NewBB, OutsideBlocks, L);
+
+ return NewBB;
}
/// RewriteLoopExitBlock - Ensure that the loop preheader dominates all exit