[llvm] r199291 - LoopVectorize: Only strip casts from integer types when replacing symbolic
Arnold Schwaighofer
aschwaighofer at apple.com
Tue Jan 14 19:35:46 PST 2014
Author: arnolds
Date: Tue Jan 14 21:35:46 2014
New Revision: 199291
URL: http://llvm.org/viewvc/llvm-project?rev=199291&view=rev
Log:
LoopVectorize: Only strip casts from integer types when replacing symbolic
strides
Fixes PR18480.
Modified:
llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/trunk/test/Transforms/LoopVectorize/version-mem-access.ll
Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=199291&r1=199290&r2=199291&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Tue Jan 14 21:35:46 2014
@@ -1072,9 +1072,10 @@ struct LoopVectorize : public LoopPass {
// LoopVectorizationCostModel.
//===----------------------------------------------------------------------===//
-static Value *stripCast(Value *V) {
+static Value *stripIntegerCast(Value *V) {
if (CastInst *CI = dyn_cast<CastInst>(V))
- return CI->getOperand(0);
+ if (CI->getOperand(0)->getType()->isIntegerTy())
+ return CI->getOperand(0);
return V;
}
@@ -1095,7 +1096,7 @@ static const SCEV *replaceSymbolicStride
Value *StrideVal = SI->second;
// Strip casts.
- StrideVal = stripCast(StrideVal);
+ StrideVal = stripIntegerCast(StrideVal);
// Replace symbolic stride by one.
Value *One = ConstantInt::get(StrideVal->getType(), 1);
@@ -1551,7 +1552,7 @@ InnerLoopVectorizer::addStrideCheck(Inst
for (SmallPtrSet<Value *, 8>::iterator SI = Legal->strides_begin(),
SE = Legal->strides_end();
SI != SE; ++SI) {
- Value *Ptr = stripCast(*SI);
+ Value *Ptr = stripIntegerCast(*SI);
Value *C = ChkBuilder.CreateICmpNE(Ptr, ConstantInt::get(Ptr->getType(), 1),
"stride.chk");
// Store the first instruction we create.
Modified: llvm/trunk/test/Transforms/LoopVectorize/version-mem-access.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/version-mem-access.ll?rev=199291&r1=199290&r2=199291&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopVectorize/version-mem-access.ll (original)
+++ llvm/trunk/test/Transforms/LoopVectorize/version-mem-access.ll Tue Jan 14 21:35:46 2014
@@ -48,3 +48,40 @@ for.end.loopexit:
for.end:
ret void
}
+
+; We used to crash on this function because we removed the fptosi cast when
+; replacing the symbolic stride '%conv'.
+; PR18480
+
+; CHECK-LABEL: fn1
+; CHECK: load <2 x double>
+
+define void @fn1(double* noalias %x, double* noalias %c, double %a) {
+entry:
+ %conv = fptosi double %a to i32
+ %cmp8 = icmp sgt i32 %conv, 0
+ br i1 %cmp8, label %for.body.preheader, label %for.end
+
+for.body.preheader:
+ br label %for.body
+
+for.body:
+ %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
+ %0 = trunc i64 %indvars.iv to i32
+ %mul = mul nsw i32 %0, %conv
+ %idxprom = sext i32 %mul to i64
+ %arrayidx = getelementptr inbounds double* %x, i64 %idxprom
+ %1 = load double* %arrayidx, align 8
+ %arrayidx3 = getelementptr inbounds double* %c, i64 %indvars.iv
+ store double %1, double* %arrayidx3, align 8
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ %lftr.wideiv = trunc i64 %indvars.iv.next to i32
+ %exitcond = icmp eq i32 %lftr.wideiv, %conv
+ br i1 %exitcond, label %for.end.loopexit, label %for.body
+
+for.end.loopexit:
+ br label %for.end
+
+for.end:
+ ret void
+}
More information about the llvm-commits
mailing list