summaryrefslogtreecommitdiff
path: root/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-02-22 03:21:39 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-02-22 03:21:39 +0000
commit919a503458c18472984c7c37b305110c9ba3a782 (patch)
treec279b9ee5861f0fd3dabbfbf51581382d066e4da /lib/Analysis/ScalarEvolutionExpander.cpp
parent57708abb10223a1a57334549c23eb93e5bbf18e6 (diff)
downloadllvm-919a503458c18472984c7c37b305110c9ba3a782.tar.gz
llvm-919a503458c18472984c7c37b305110c9ba3a782.tar.bz2
llvm-919a503458c18472984c7c37b305110c9ba3a782.tar.xz
Semantically revert 151015. Add a comment on why we should be able to assert
the dominance once the dominates method is fixed and why we can use the builder's insertion point. Fixes pr12048. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151125 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index c76633285c..a9473b4c49 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -31,11 +31,20 @@ using namespace llvm;
Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
Instruction::CastOps Op,
BasicBlock::iterator IP) {
- // All new or reused instructions must strictly dominate their uses.
- // It would be nice to assert this here, but we don't always know where
- // the next instructions will be added as the caller can move the
- // Builder's InsertPt before creating them and we might be called with
- // an invalid InsertPt.
+ // This function must be called with the builder having a valid insertion
+ // point. It doesn't need to be the actual IP where the uses of the returned
+ // cast will be added, but it must dominate such IP.
+ // We use this precondition to assert that we can produce a cast that will
+ // dominate all its uses. In particular, this is crussial for the case
+ // where the builder's insertion point *is* the point where we were asked
+ // to put the cast.
+ // Since we don't know the the builder's insertion point is actually
+ // where the uses will be added (only that it dominates it), we are
+ // not allowed to move it.
+ BasicBlock::iterator BIP = Builder.GetInsertPoint();
+
+ // FIXME: enable once our implementation of dominates is fixed.
+ // assert(BIP == IP || SE.DT->dominates(IP, BIP));
// Check to see if there is already a cast!
for (Value::use_iterator UI = V->use_begin(), E = V->use_end();
@@ -44,8 +53,9 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
if (U->getType() == Ty)
if (CastInst *CI = dyn_cast<CastInst>(U))
if (CI->getOpcode() == Op) {
- // If the cast isn't where we want it, fix it.
- if (BasicBlock::iterator(CI) != IP) {
+ // If the cast isn't where we want it or if it doesn't dominate
+ // a use in BIP, fix it.
+ if (BasicBlock::iterator(CI) != IP || BIP == IP) {
// Create a new cast, and leave the old cast in place in case
// it is being used as an insert point. Clear its operand
// so that it doesn't hold anything live.