aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2011-07-16 00:59:39 +0000
committerAndrew Trick <atrick@apple.com>2011-07-16 00:59:39 +0000
commitd152d03a476b8d0d4b26577db26e2ba76034b0f3 (patch)
tree646a8a651816a75c88dd9dcab4316ff42a3e000b
parent4201ecae928e8503ffe7d53f11e3e8745fd28fe2 (diff)
downloadexternal_llvm-d152d03a476b8d0d4b26577db26e2ba76034b0f3.zip
external_llvm-d152d03a476b8d0d4b26577db26e2ba76034b0f3.tar.gz
external_llvm-d152d03a476b8d0d4b26577db26e2ba76034b0f3.tar.bz2
Fix SCEVEXpander to handle arbitrary phi expansion. Includes two
related bug fixes and corresponding assertions for uninitialized data and missing NULL check. Test cases will be included with the new LFTR. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135333 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/ScalarEvolutionExpander.h4
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp25
2 files changed, 20 insertions, 9 deletions
diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h
index 647a7dc..a8c03b2 100644
--- a/include/llvm/Analysis/ScalarEvolutionExpander.h
+++ b/include/llvm/Analysis/ScalarEvolutionExpander.h
@@ -72,8 +72,8 @@ namespace llvm {
public:
/// SCEVExpander - Construct a SCEVExpander in "canonical" mode.
explicit SCEVExpander(ScalarEvolution &se, const char *name)
- : SE(se), IVName(name), IVIncInsertLoop(0), CanonicalMode(true),
- Builder(se.getContext(), TargetFolder(se.TD)) {}
+ : SE(se), IVName(name), IVIncInsertLoop(0), IVIncInsertPos(0),
+ CanonicalMode(true), Builder(se.getContext(), TargetFolder(se.TD)) {}
/// clear - Erase the contents of the InsertedExpressions map so that users
/// trying to expand the same expression into multiple BasicBlocks or
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index 9f6063e..478f555 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -19,6 +19,7 @@
#include "llvm/LLVMContext.h"
#include "llvm/Target/TargetData.h"
#include "llvm/ADT/STLExtras.h"
+
using namespace llvm;
/// ReuseOrCreateCast - Arrange for there to be a cast of V to Ty at IP,
@@ -848,6 +849,8 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
const Loop *L,
const Type *ExpandTy,
const Type *IntTy) {
+ assert(!IVIncInsertLoop || IVIncInsertPos && "Uninitialized insert position");
+
// Reuse a previously-inserted PHI, if present.
for (BasicBlock::iterator I = L->getHeader()->begin();
PHINode *PN = dyn_cast<PHINode>(I); ++I)
@@ -872,13 +875,15 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
// If any of the operands don't dominate the insert position, bail.
// Addrec operands are always loop-invariant, so this can only happen
// if there are instructions which haven't been hoisted.
- for (User::op_iterator OI = IncV->op_begin()+1,
- OE = IncV->op_end(); OI != OE; ++OI)
- if (Instruction *OInst = dyn_cast<Instruction>(OI))
- if (!SE.DT->dominates(OInst, IVIncInsertPos)) {
- IncV = 0;
- break;
- }
+ if (L == IVIncInsertLoop) {
+ for (User::op_iterator OI = IncV->op_begin()+1,
+ OE = IncV->op_end(); OI != OE; ++OI)
+ if (Instruction *OInst = dyn_cast<Instruction>(OI))
+ if (!SE.DT->dominates(OInst, IVIncInsertPos)) {
+ IncV = 0;
+ break;
+ }
+ }
if (!IncV)
break;
// Advance to the next instruction.
@@ -920,6 +925,12 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
Value *StartV = expandCodeFor(Normalized->getStart(), ExpandTy,
L->getHeader()->begin());
+ // StartV must be hoisted into L's preheader to dominate the new phi.
+ Instruction *StartI = dyn_cast<Instruction>(StartV);
+ assert(!StartI || SE.DT->properlyDominates(StartI->getParent(),
+ L->getHeader()) && "");
+ (void)StartI;
+
// Expand code for the step value. Insert instructions right before the
// terminator corresponding to the back-edge. Do this before creating the PHI
// so that PHI reuse code doesn't see an incomplete PHI. If the stride is