diff options
author | Tobias Grosser <tobias@grosser.es> | 2015-09-17 20:16:21 +0000 |
---|---|---|
committer | Tobias Grosser <tobias@grosser.es> | 2015-09-17 20:16:21 +0000 |
commit | 6f36d9ab01cf5c385590fea96481b742c8ce65cf (patch) | |
tree | 60d16b2f8ba71fa1c9d42206b8668e72e8baf1a3 | |
parent | ff642b9b84e0c8d226f4d7ce2ae2853a89b08cda (diff) | |
download | bcm5719-llvm-6f36d9ab01cf5c385590fea96481b742c8ce65cf.tar.gz bcm5719-llvm-6f36d9ab01cf5c385590fea96481b742c8ce65cf.zip |
Delinearize multi-dimensional arrays through bitcasts
In some cases instcombine introduces bitcasts that slightly obfuscate the
multi-dimensionality of an array. This patch teaches our fixed-size
delinearization how to look through bitcasts.
llvm-svn: 247928
-rw-r--r-- | polly/lib/Analysis/ScopInfo.cpp | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index b1fa5804d74..ae608ebfb56 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -2925,30 +2925,41 @@ ScopInfo::buildIRAccess(Instruction *Inst, Loop *L, Region *R, assert(BasePointer && "Could not find base pointer"); AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer); - if (auto *GEP = dyn_cast<GetElementPtrInst>(Address)) { - std::vector<const SCEV *> Subscripts; - std::vector<int> Sizes; - std::tie(Subscripts, Sizes) = getIndexExpressionsFromGEP(GEP, *SE); - auto BasePtr = GEP->getOperand(0); - - std::vector<const SCEV *> SizesSCEV; - - bool AllAffineSubcripts = true; - for (auto Subscript : Subscripts) - if (!isAffineExpr(R, Subscript, *SE)) { - AllAffineSubcripts = false; - break; - } + if (isa<GetElementPtrInst>(Address) || isa<BitCastInst>(Address)) { + auto NewAddress = Address; + if (auto *BitCast = dyn_cast<BitCastInst>(Address)) { + auto Src = BitCast->getOperand(0); + auto SrcTy = Src->getType(); + auto DstTy = BitCast->getType(); + if (SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits()) + NewAddress = Src; + } + + if (auto *GEP = dyn_cast<GetElementPtrInst>(NewAddress)) { + std::vector<const SCEV *> Subscripts; + std::vector<int> Sizes; + std::tie(Subscripts, Sizes) = getIndexExpressionsFromGEP(GEP, *SE); + auto BasePtr = GEP->getOperand(0); - if (AllAffineSubcripts && Sizes.size() > 0) { - for (auto V : Sizes) + std::vector<const SCEV *> SizesSCEV; + + bool AllAffineSubcripts = true; + for (auto Subscript : Subscripts) + if (!isAffineExpr(R, Subscript, *SE)) { + AllAffineSubcripts = false; + break; + } + + if (AllAffineSubcripts && Sizes.size() > 0) { + for (auto V : Sizes) + SizesSCEV.push_back(SE->getSCEV(ConstantInt::get( + IntegerType::getInt64Ty(BasePtr->getContext()), V))); SizesSCEV.push_back(SE->getSCEV(ConstantInt::get( - IntegerType::getInt64Ty(BasePtr->getContext()), V))); - SizesSCEV.push_back(SE->getSCEV(ConstantInt::get( - IntegerType::getInt64Ty(BasePtr->getContext()), Size))); + IntegerType::getInt64Ty(BasePtr->getContext()), Size))); - return IRAccess(Type, BasePointer->getValue(), AccessFunction, Size, true, - Subscripts, SizesSCEV, Val); + return IRAccess(Type, BasePointer->getValue(), AccessFunction, Size, + true, Subscripts, SizesSCEV, Val); + } } } |