summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorMatthew Simpson <mssimpso@codeaurora.org>2018-03-15 16:00:29 +0000
committerMatthew Simpson <mssimpso@codeaurora.org>2018-03-15 16:00:29 +0000
commitc1c4ad6e64fc0037f4f21952bc6d1a569bce2fa1 (patch)
tree4336aca3876235b0a7e20243a3ae58b4ea25bdbb /llvm/lib/IR/ConstantFold.cpp
parentf3de222b0d3c169985ba9d61f479f3e8a3675100 (diff)
downloadbcm5719-llvm-c1c4ad6e64fc0037f4f21952bc6d1a569bce2fa1.tar.gz
bcm5719-llvm-c1c4ad6e64fc0037f4f21952bc6d1a569bce2fa1.zip
[ConstantFolding, InstSimplify] Handle more vector GEPs
This patch addresses some additional cases where the compiler crashes upon encountering vector GEPs. This should fix PR36116. Differential Revision: https://reviews.llvm.org/D44219 Reference: https://bugs.llvm.org/show_bug.cgi?id=36116 llvm-svn: 327638
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 92d35a27d69..7ad2d46bfb6 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -2027,8 +2027,16 @@ static bool isInBoundsIndices(ArrayRef<IndexTy> Idxs) {
// If the first index is one and all the rest are zero, it's in bounds,
// by the one-past-the-end rule.
- if (!cast<ConstantInt>(Idxs[0])->isOne())
- return false;
+ if (auto *CI = dyn_cast<ConstantInt>(Idxs[0])) {
+ if (!CI->isOne())
+ return false;
+ } else {
+ auto *CV = cast<ConstantDataVector>(Idxs[0]);
+ CI = dyn_cast_or_null<ConstantInt>(CV->getSplatValue());
+ if (!CI || !CI->isOne())
+ return false;
+ }
+
for (unsigned i = 1, e = Idxs.size(); i != e; ++i)
if (!cast<Constant>(Idxs[i])->isNullValue())
return false;
@@ -2058,15 +2066,18 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
ArrayRef<Value *> Idxs) {
if (Idxs.empty()) return C;
- if (isa<UndefValue>(C)) {
- Type *GEPTy = GetElementPtrInst::getGEPReturnType(
- C, makeArrayRef((Value * const *)Idxs.data(), Idxs.size()));
+ Type *GEPTy = GetElementPtrInst::getGEPReturnType(
+ C, makeArrayRef((Value *const *)Idxs.data(), Idxs.size()));
+
+ if (isa<UndefValue>(C))
return UndefValue::get(GEPTy);
- }
Constant *Idx0 = cast<Constant>(Idxs[0]);
if (Idxs.size() == 1 && (Idx0->isNullValue() || isa<UndefValue>(Idx0)))
- return C;
+ return GEPTy->isVectorTy() && !C->getType()->isVectorTy()
+ ? ConstantVector::getSplat(
+ cast<VectorType>(GEPTy)->getNumElements(), C)
+ : C;
if (C->isNullValue()) {
bool isNull = true;
OpenPOWER on IntegriCloud