diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp index 515dc41a55ea..b9ffe7e5b7af 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp @@ -35,6 +35,12 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) { CachedTypes[OtherV] = ResTy; return ResTy; } + case Instruction::ICmp: { + // TODO: Check if types for both operands agree. This also requires + // type-inference for the vector-trip-count, which is missing at the moment. + Type *ResTy = inferScalarType(R->getOperand(0)); + return ResTy; + } case VPInstruction::FirstOrderRecurrenceSplice: { Type *ResTy = inferScalarType(R->getOperand(0)); VPValue *OtherV = R->getOperand(1); diff --git a/llvm/test/Transforms/LoopVectorize/cast-induction.ll b/llvm/test/Transforms/LoopVectorize/cast-induction.ll index ae5acba63820..782efb7acc64 100644 --- a/llvm/test/Transforms/LoopVectorize/cast-induction.ll +++ b/llvm/test/Transforms/LoopVectorize/cast-induction.ll @@ -115,3 +115,34 @@ loop: exit: ret void } + +define void @cast_induction_tail_folding(ptr %A) { +; VF4-LABEL: @cast_induction_tail_folding( +; VF4: [[INDEX:%.+]] = phi i32 [ 0, %vector.ph ] +; VF4-NEXT: [[VEC_IND:%.+]] = phi <4 x i32> [ , %vector.ph ] +; VF4-NEXT: = icmp ule <4 x i32> [[VEC_IND]], +; VF4-NEXT: = sext <4 x i32> [[VEC_IND]] to <4 x i64> + +; IC2-LABEL: @cast_induction_tail_folding( +; IC2: [[INDEX:%.+]] = phi i32 [ 0, %vector.ph ] +; IC2-NEXT: [[INDEX0:%.+]] = add i32 [[INDEX]], 0 +; IC2-NEXT: [[INDEX1:%.+]] = add i32 [[INDEX]], 1 +; IC2-NEXT: = icmp ule i32 [[INDEX0]], 2 +; IC2-NEXT: = icmp ule i32 [[INDEX1]], 2 +; +entry: + br label %loop + +loop: + %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ] + %iv.ext = sext i32 %iv to i64 + %iv.trunc = trunc i64 %iv.ext to i32 + %gep = getelementptr inbounds i32, ptr %A, i64 %iv.ext + store i32 %iv.trunc, ptr %gep + %iv.next = add i32 %iv, 1 + %c = icmp slt i32 %iv.next, 3 + br i1 %c, label %loop, label %exit + +exit: + ret void +}