llvm.org GIT mirror llvm / e96fec2
LoopVectorize: Only strip casts from integer types when replacing symbolic strides Fixes PR18480. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199291 91177308-0d34-0410-b5e6-96231b3b80d8 Arnold Schwaighofer 6 years ago
2 changed file(s) with 42 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
10711071 // LoopVectorizationCostModel.
10721072 //===----------------------------------------------------------------------===//
10731073
1074 static Value *stripCast(Value *V) {
1074 static Value *stripIntegerCast(Value *V) {
10751075 if (CastInst *CI = dyn_cast(V))
1076 return CI->getOperand(0);
1076 if (CI->getOperand(0)->getType()->isIntegerTy())
1077 return CI->getOperand(0);
10771078 return V;
10781079 }
10791080
10941095 Value *StrideVal = SI->second;
10951096
10961097 // Strip casts.
1097 StrideVal = stripCast(StrideVal);
1098 StrideVal = stripIntegerCast(StrideVal);
10981099
10991100 // Replace symbolic stride by one.
11001101 Value *One = ConstantInt::get(StrideVal->getType(), 1);
15501551 for (SmallPtrSet::iterator SI = Legal->strides_begin(),
15511552 SE = Legal->strides_end();
15521553 SI != SE; ++SI) {
1553 Value *Ptr = stripCast(*SI);
1554 Value *Ptr = stripIntegerCast(*SI);
15541555 Value *C = ChkBuilder.CreateICmpNE(Ptr, ConstantInt::get(Ptr->getType(), 1),
15551556 "stride.chk");
15561557 // Store the first instruction we create.
4747 for.end:
4848 ret void
4949 }
50
51 ; We used to crash on this function because we removed the fptosi cast when
52 ; replacing the symbolic stride '%conv'.
53 ; PR18480
54
55 ; CHECK-LABEL: fn1
56 ; CHECK: load <2 x double>
57
58 define void @fn1(double* noalias %x, double* noalias %c, double %a) {
59 entry:
60 %conv = fptosi double %a to i32
61 %cmp8 = icmp sgt i32 %conv, 0
62 br i1 %cmp8, label %for.body.preheader, label %for.end
63
64 for.body.preheader:
65 br label %for.body
66
67 for.body:
68 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
69 %0 = trunc i64 %indvars.iv to i32
70 %mul = mul nsw i32 %0, %conv
71 %idxprom = sext i32 %mul to i64
72 %arrayidx = getelementptr inbounds double* %x, i64 %idxprom
73 %1 = load double* %arrayidx, align 8
74 %arrayidx3 = getelementptr inbounds double* %c, i64 %indvars.iv
75 store double %1, double* %arrayidx3, align 8
76 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
77 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
78 %exitcond = icmp eq i32 %lftr.wideiv, %conv
79 br i1 %exitcond, label %for.end.loopexit, label %for.body
80
81 for.end.loopexit:
82 br label %for.end
83
84 for.end:
85 ret void
86 }