diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-06-17 16:35:35 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-06-23 16:14:36 -0700 |
commit | 90ad786947cc861756c95238f96c267b2a3c4849 (patch) | |
tree | 1c90a2e18b14b1102b38c5342c9bac41547c068a /llvm/lib/IR/Constants.cpp | |
parent | 723b5a1785426245e3c56b4666ef526b32be84a9 (diff) | |
download | llvm-90ad786947cc861756c95238f96c267b2a3c4849.zip llvm-90ad786947cc861756c95238f96c267b2a3c4849.tar.gz llvm-90ad786947cc861756c95238f96c267b2a3c4849.tar.bz2 |
[IR] Prefer scalar type for struct indexes in GEP constant expressions.
This has two advantages: one, it's simpler, and two, it doesn't require
heroic pattern matching with scalable vectors.
Also includes a small fix to DataLayout to allow the scalable vector
testcase to work correctly.
Differential Revision: https://reviews.llvm.org/D82061
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index daa15bb2..1afd73d 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2175,15 +2175,20 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, std::vector<Constant*> ArgVec; ArgVec.reserve(1 + Idxs.size()); ArgVec.push_back(C); - for (unsigned i = 0, e = Idxs.size(); i != e; ++i) { + auto GTI = gep_type_begin(Ty, Idxs), GTE = gep_type_end(Ty, Idxs); + for (; GTI != GTE; ++GTI) { + auto *Idx = cast<Constant>(GTI.getOperand()); assert( - (!isa<VectorType>(Idxs[i]->getType()) || - cast<VectorType>(Idxs[i]->getType())->getElementCount() == EltCount) && + (!isa<VectorType>(Idx->getType()) || + cast<VectorType>(Idx->getType())->getElementCount() == EltCount) && "getelementptr index type missmatch"); - Constant *Idx = cast<Constant>(Idxs[i]); - if (EltCount.Min != 0 && !Idxs[i]->getType()->isVectorTy()) + if (GTI.isStruct() && Idx->getType()->isVectorTy()) { + Idx = Idx->getSplatValue(); + } else if (GTI.isSequential() && EltCount.Min != 0 && + !Idx->getType()->isVectorTy()) { Idx = ConstantVector::getSplat(EltCount, Idx); + } ArgVec.push_back(Idx); } |