[VPlan] Implement type inference for ICmp.

This fixes a crash in the attached test case due to missing type
inference for ICmp VPInstructions.
This commit is contained in:
Florian Hahn 2024-02-05 15:42:07 +00:00
parent 4881cbd407
commit 8cb2de7fae
No known key found for this signature in database
GPG Key ID: 9E54DEA47A8F4434
2 changed files with 37 additions and 0 deletions

View File

@ -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);

View File

@ -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
}