llvm.org GIT mirror llvm / 8a8d8b3
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240877 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
2 changed file(s) with 30 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
849849 return B.CreateAdd(StartValue, Index);
850850
851851 case IK_PtrInduction:
852 assert(Index->getType() == StepValue->getType() &&
853 "Index type does not match StepValue type");
852854 if (StepValue->isMinusOne())
853855 Index = B.CreateNeg(Index);
854856 else if (!StepValue->isOne())
27972799 break;
27982800 }
27992801 case LoopVectorizationLegality::IK_PtrInduction: {
2800 EndValue = II.transform(BypassBuilder, CountRoundDown);
2802 Value *CRD = BypassBuilder.CreateSExtOrTrunc(CountRoundDown,
2803 II.StepValue->getType(),
2804 "cast.crd");
2805 EndValue = II.transform(BypassBuilder, CRD);
28012806 EndValue->setName("ptr.ind.end");
28022807 break;
28032808 }
34473452 // This is the normalized GEP that starts counting at zero.
34483453 Value *NormalizedIdx =
34493454 Builder.CreateSub(Induction, ExtendedIdx, "normalized.idx");
3455 NormalizedIdx =
3456 Builder.CreateSExtOrTrunc(NormalizedIdx, II.StepValue->getType());
34503457 // This is the vector of results. Notice that we don't generate
34513458 // vector geps because scalar geps result in better code.
34523459 for (unsigned part = 0; part < UF; ++part) {
34533460 if (VF == 1) {
34543461 int EltIndex = part;
3455 Constant *Idx = ConstantInt::get(Induction->getType(), EltIndex);
3462 Constant *Idx = ConstantInt::get(NormalizedIdx->getType(), EltIndex);
34563463 Value *GlobalIdx = Builder.CreateAdd(NormalizedIdx, Idx);
34573464 Value *SclrGep = II.transform(Builder, GlobalIdx);
34583465 SclrGep->setName("next.gep");
34633470 Value *VecVal = UndefValue::get(VectorType::get(P->getType(), VF));
34643471 for (unsigned int i = 0; i < VF; ++i) {
34653472 int EltIndex = i + part * VF;
3466 Constant *Idx = ConstantInt::get(Induction->getType(), EltIndex);
3473 Constant *Idx = ConstantInt::get(NormalizedIdx->getType(), EltIndex);
34673474 Value *GlobalIdx = Builder.CreateAdd(NormalizedIdx, Idx);
34683475 Value *SclrGep = II.transform(Builder, GlobalIdx);
34693476 SclrGep->setName("next.gep");
0 ; RUN: opt -slp-vectorizer -S %s
1
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 define void @f(i128 %p1) {
6 entry:
7 br label %while.body
8
9 while.body:
10 %p.05 = phi i8* [ %add.ptr, %while.body ], [ null, %entry ]
11 %p1.addr.04 = phi i128 [ %sub, %while.body ], [ %p1, %entry ]
12 %add.ptr = getelementptr inbounds i8, i8* %p.05, i32 2
13 %sub = add nsw i128 %p1.addr.04, -2
14 %tobool = icmp eq i128 %sub, 0
15 br i1 %tobool, label %while.end, label %while.body
16
17 while.end:
18 ret void
19 }