[llvm] 8cb2de7 - [VPlan] Implement type inference for ICmp.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 07:42:28 PST 2024
Author: Florian Hahn
Date: 2024-02-05T15:42:07Z
New Revision: 8cb2de7faecdd4e053dfc8468b2be84e2d8afb4e
URL: https://github.com/llvm/llvm-project/commit/8cb2de7faecdd4e053dfc8468b2be84e2d8afb4e
DIFF: https://github.com/llvm/llvm-project/commit/8cb2de7faecdd4e053dfc8468b2be84e2d8afb4e.diff
LOG: [VPlan] Implement type inference for ICmp.
This fixes a crash in the attached test case due to missing type
inference for ICmp VPInstructions.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
llvm/test/Transforms/LoopVectorize/cast-induction.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 515dc41a55ea1..b9ffe7e5b7af7 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 ae5acba638202..782efb7acc644 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> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ]
+; VF4-NEXT: = icmp ule <4 x i32> [[VEC_IND]], <i32 2, i32 2, i32 2, i32 2>
+; 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
+}
More information about the llvm-commits
mailing list