Skip bitcasts while looking for GEP in LoadStoreVectorizer

Differential Revisison: https://reviews.llvm.org/D32101

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301343 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Stanislav Mekhanoshin
2017-04-25 18:00:08 +00:00
parent 410317e973
commit dff33b262e
2 changed files with 102 additions and 4 deletions
@@ -65,7 +65,9 @@ public:
bool run();
private:
Value *getPointerOperand(Value *I);
Value *getPointerOperand(Value *I) const;
GetElementPtrInst *getSourceGEP(Value *Src) const;
unsigned getPointerAddressSpace(Value *I);
@@ -215,7 +217,7 @@ bool Vectorizer::run() {
return Changed;
}
Value *Vectorizer::getPointerOperand(Value *I) {
Value *Vectorizer::getPointerOperand(Value *I) const {
if (LoadInst *LI = dyn_cast<LoadInst>(I))
return LI->getPointerOperand();
if (StoreInst *SI = dyn_cast<StoreInst>(I))
@@ -231,6 +233,19 @@ unsigned Vectorizer::getPointerAddressSpace(Value *I) {
return -1;
}
GetElementPtrInst *Vectorizer::getSourceGEP(Value *Src) const {
// First strip pointer bitcasts. Make sure pointee size is the same with
// and without casts.
// TODO: a stride set by the add instruction below can match the difference
// in pointee type size here. Currently it will not be vectorized.
Value *SrcPtr = getPointerOperand(Src);
Value *SrcBase = SrcPtr->stripPointerCasts();
if (DL.getTypeStoreSize(SrcPtr->getType()->getPointerElementType()) ==
DL.getTypeStoreSize(SrcBase->getType()->getPointerElementType()))
SrcPtr = SrcBase;
return dyn_cast<GetElementPtrInst>(SrcPtr);
}
// FIXME: Merge with llvm::isConsecutiveAccess
bool Vectorizer::isConsecutiveAccess(Value *A, Value *B) {
Value *PtrA = getPointerOperand(A);
@@ -283,8 +298,8 @@ bool Vectorizer::isConsecutiveAccess(Value *A, Value *B) {
// Look through GEPs after checking they're the same except for the last
// index.
GetElementPtrInst *GEPA = dyn_cast<GetElementPtrInst>(getPointerOperand(A));
GetElementPtrInst *GEPB = dyn_cast<GetElementPtrInst>(getPointerOperand(B));
GetElementPtrInst *GEPA = getSourceGEP(A);
GetElementPtrInst *GEPB = getSourceGEP(B);
if (!GEPA || !GEPB || GEPA->getNumOperands() != GEPB->getNumOperands())
return false;
unsigned FinalIndex = GEPA->getNumOperands() - 1;