aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorMichael Kuperstein <mkuper@google.com>2016-12-21 17:34:21 +0000
committerMichael Kuperstein <mkuper@google.com>2016-12-21 17:34:21 +0000
commitdd92c78669da0c3e0c285b0723ee5ecba12ca1df (patch)
tree9184dcff28859e42ff18938bfa69426285efa550 /llvm/lib/Analysis/ConstantFolding.cpp
parent083d1700a0ef03d98db2109fd76186889f3c3fbe (diff)
downloadllvm-dd92c78669da0c3e0c285b0723ee5ecba12ca1df.zip
llvm-dd92c78669da0c3e0c285b0723ee5ecba12ca1df.tar.gz
llvm-dd92c78669da0c3e0c285b0723ee5ecba12ca1df.tar.bz2
[ConstantFolding] Fix vector GEPs harder
For vector GEPs, CastGEPIndices can end up in an infinite recursion, because we compare the vector type to the scalar pointer type, find them different, and then try to cast a type to itself. Differential Revision: https://reviews.llvm.org/D28009 llvm-svn: 290260
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index cf0d5e4..9e521e1 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -742,13 +742,16 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
if ((i == 1 ||
!isa<StructType>(GetElementPtrInst::getIndexedType(
SrcElemTy, Ops.slice(1, i - 1)))) &&
- Ops[i]->getType() != (i == 1 ? IntPtrTy : IntPtrScalarTy)) {
+ Ops[i]->getType()->getScalarType() != IntPtrScalarTy) {
Any = true;
+ Type *NewType = Ops[i]->getType()->isVectorTy()
+ ? IntPtrTy
+ : IntPtrTy->getScalarType();
NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i],
true,
- IntPtrTy,
+ NewType,
true),
- Ops[i], IntPtrTy));
+ Ops[i], NewType));
} else
NewIdxs.push_back(Ops[i]);
}