aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2021-04-19 18:30:56 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2021-04-19 18:38:39 +0300
commitd746fefb6ffde82bc6ea4e2ccf6c637ee521423e (patch)
treeb3d2b20dac15174f2d215a6cda3bcb20a9b0e263 /llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
parentecc9d7e913eec96816499d0a328c6134281f8aad (diff)
downloadllvm-d746fefb6ffde82bc6ea4e2ccf6c637ee521423e.zip
llvm-d746fefb6ffde82bc6ea4e2ccf6c637ee521423e.tar.gz
llvm-d746fefb6ffde82bc6ea4e2ccf6c637ee521423e.tar.bz2
[SCEVExpander] ReuseOrCreateCast(): use IRBuilder to actually create the cast
In particular, this allows to create constant expressions instead of IR Instruction's if the argumen is a constant.
Diffstat (limited to 'llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 2e96743..815f7b1 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -55,7 +55,7 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
// not allowed to move it.
BasicBlock::iterator BIP = Builder.GetInsertPoint();
- Instruction *Ret = nullptr;
+ Value *Ret = nullptr;
// Check to see if there is already a cast!
for (User *U : V->users()) {
@@ -76,14 +76,16 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
// Create a new cast.
if (!Ret) {
- Ret = CastInst::Create(Op, V, Ty, V->getName(), &*IP);
- rememberInstruction(Ret);
+ SCEVInsertPointGuard Guard(Builder, this);
+ Builder.SetInsertPoint(&*IP);
+ Ret = Builder.CreateCast(Op, V, Ty, V->getName());
}
// We assert at the end of the function since IP might point to an
// instruction with different dominance properties than a cast
// (an invoke for example) and not dominate BIP (but the cast does).
- assert(SE.DT.dominates(Ret, &*BIP));
+ assert(!isa<Instruction>(Ret) ||
+ SE.DT.dominates(cast<Instruction>(Ret), &*BIP));
return Ret;
}