From 8f924f3891dddd750d63ab191afc35b57572a956 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Tue, 16 Jul 2013 22:51:07 +0000 Subject: [PATCH] SLPVectorizer: Improve the compile time of isConsecutive by adding a simple constant-gep check before using SCEV. This check does not always work because not all of the GEPs use a constant offset, but it happens often enough to reduce the number of times we use SCEV. llvm-svn: 186465 --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 50ca697..c1e8111 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -983,6 +983,24 @@ bool BoUpSLP::isConsecutiveAccess(Value *A, Value *B) { if (PtrA->getType() != PtrB->getType()) return false; + // Calculate a constant offset from the base pointer without using SCEV + // in the supported cases. + // TODO: Add support for the case where one of the pointers is a GEP that + // uses the other pointer. + GetElementPtrInst *GepA = dyn_cast(PtrA); + GetElementPtrInst *GepB = dyn_cast(PtrB); + if (GepA && GepB && GepA->getPointerOperand() == GepB->getPointerOperand()) { + unsigned BW = DL->getPointerSizeInBits(ASA); + APInt OffsetA(BW, 0) ,OffsetB(BW, 0); + + if (GepA->accumulateConstantOffset(*DL, OffsetA) && + GepB->accumulateConstantOffset(*DL, OffsetB)) { + Type *Ty = cast(PtrA->getType())->getElementType(); + int64_t Sz = DL->getTypeStoreSize(Ty); + return ((OffsetB.getSExtValue() - OffsetA.getSExtValue()) == Sz); + } + } + // Calculate the distance. const SCEV *PtrSCEVA = SE->getSCEV(PtrA); const SCEV *PtrSCEVB = SE->getSCEV(PtrB); -- 2.7.4