[llvm] r240877 - [LoopVectorize] Pointer indicies may be wider than the pointer

Michael Zolotukhin mzolotukhin at apple.com
Mon Jun 29 15:58:52 PDT 2015


Hi David,

> +; RUN: opt -slp-vectorizer -S %s
Is this a typo? Was it supposed to be ‘-loop-vectorize’?

Thanks,
Michael

> On Jun 27, 2015, at 1:38 AM, David Majnemer <david.majnemer at gmail.com> wrote:
> 
> Author: majnemer
> Date: Sat Jun 27 03:38:17 2015
> New Revision: 240877
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=240877&view=rev
> Log:
> [LoopVectorize] Pointer indicies may be wider than the pointer
> 
> If we are dealing with a pointer induction variable, isInductionPHI
> gives back a step value of Stride / size of pointer.  However, we might
> be indexing with a legal type wider than the pointer width.
> Handle this by inserting casts where appropriate instead of crashing.
> 
> This fixes PR23954.
> 
> Added:
>    llvm/trunk/test/Transforms/LoopVectorize/X86/ptr-indvar-crash.ll
> Modified:
>    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
> 
> Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=240877&r1=240876&r2=240877&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
> +++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Sat Jun 27 03:38:17 2015
> @@ -850,6 +850,8 @@ public:
>         return B.CreateAdd(StartValue, Index);
> 
>       case IK_PtrInduction:
> +        assert(Index->getType() == StepValue->getType() &&
> +               "Index type does not match StepValue type");
>         if (StepValue->isMinusOne())
>           Index = B.CreateNeg(Index);
>         else if (!StepValue->isOne())
> @@ -2798,7 +2800,10 @@ void InnerLoopVectorizer::createEmptyLoo
>       break;
>     }
>     case LoopVectorizationLegality::IK_PtrInduction: {
> -      EndValue = II.transform(BypassBuilder, CountRoundDown);
> +      Value *CRD = BypassBuilder.CreateSExtOrTrunc(CountRoundDown,
> +                                                   II.StepValue->getType(),
> +                                                   "cast.crd");
> +      EndValue = II.transform(BypassBuilder, CRD);
>       EndValue->setName("ptr.ind.end");
>       break;
>     }
> @@ -3448,12 +3453,14 @@ void InnerLoopVectorizer::widenPHIInstru
>       // This is the normalized GEP that starts counting at zero.
>       Value *NormalizedIdx =
>           Builder.CreateSub(Induction, ExtendedIdx, "normalized.idx");
> +      NormalizedIdx =
> +          Builder.CreateSExtOrTrunc(NormalizedIdx, II.StepValue->getType());
>       // This is the vector of results. Notice that we don't generate
>       // vector geps because scalar geps result in better code.
>       for (unsigned part = 0; part < UF; ++part) {
>         if (VF == 1) {
>           int EltIndex = part;
> -          Constant *Idx = ConstantInt::get(Induction->getType(), EltIndex);
> +          Constant *Idx = ConstantInt::get(NormalizedIdx->getType(), EltIndex);
>           Value *GlobalIdx = Builder.CreateAdd(NormalizedIdx, Idx);
>           Value *SclrGep = II.transform(Builder, GlobalIdx);
>           SclrGep->setName("next.gep");
> @@ -3464,7 +3471,7 @@ void InnerLoopVectorizer::widenPHIInstru
>         Value *VecVal = UndefValue::get(VectorType::get(P->getType(), VF));
>         for (unsigned int i = 0; i < VF; ++i) {
>           int EltIndex = i + part * VF;
> -          Constant *Idx = ConstantInt::get(Induction->getType(), EltIndex);
> +          Constant *Idx = ConstantInt::get(NormalizedIdx->getType(), EltIndex);
>           Value *GlobalIdx = Builder.CreateAdd(NormalizedIdx, Idx);
>           Value *SclrGep = II.transform(Builder, GlobalIdx);
>           SclrGep->setName("next.gep");
> 
> Added: llvm/trunk/test/Transforms/LoopVectorize/X86/ptr-indvar-crash.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/X86/ptr-indvar-crash.ll?rev=240877&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/LoopVectorize/X86/ptr-indvar-crash.ll (added)
> +++ llvm/trunk/test/Transforms/LoopVectorize/X86/ptr-indvar-crash.ll Sat Jun 27 03:38:17 2015
> @@ -0,0 +1,20 @@
> +; RUN: opt -slp-vectorizer -S %s
> +
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-unknown-linux-gnu"
> +
> +define void @f(i128 %p1) {
> +entry:
> +  br label %while.body
> +
> +while.body:
> +  %p.05 = phi i8* [ %add.ptr, %while.body ], [ null, %entry ]
> +  %p1.addr.04 = phi i128 [ %sub, %while.body ], [ %p1, %entry ]
> +  %add.ptr = getelementptr inbounds i8, i8* %p.05, i32 2
> +  %sub = add nsw i128 %p1.addr.04, -2
> +  %tobool = icmp eq i128 %sub, 0
> +  br i1 %tobool, label %while.end, label %while.body
> +
> +while.end:
> +  ret void
> +}
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list