Skip to content

Commit 8cb2de7

Browse files
committed
[VPlan] Implement type inference for ICmp.
This fixes a crash in the attached test case due to missing type inference for ICmp VPInstructions.
1 parent 4881cbd commit 8cb2de7

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
3535
CachedTypes[OtherV] = ResTy;
3636
return ResTy;
3737
}
38+
case Instruction::ICmp: {
39+
// TODO: Check if types for both operands agree. This also requires
40+
// type-inference for the vector-trip-count, which is missing at the moment.
41+
Type *ResTy = inferScalarType(R->getOperand(0));
42+
return ResTy;
43+
}
3844
case VPInstruction::FirstOrderRecurrenceSplice: {
3945
Type *ResTy = inferScalarType(R->getOperand(0));
4046
VPValue *OtherV = R->getOperand(1);

llvm/test/Transforms/LoopVectorize/cast-induction.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,34 @@ loop:
115115
exit:
116116
ret void
117117
}
118+
119+
define void @cast_induction_tail_folding(ptr %A) {
120+
; VF4-LABEL: @cast_induction_tail_folding(
121+
; VF4: [[INDEX:%.+]] = phi i32 [ 0, %vector.ph ]
122+
; VF4-NEXT: [[VEC_IND:%.+]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ]
123+
; VF4-NEXT: = icmp ule <4 x i32> [[VEC_IND]], <i32 2, i32 2, i32 2, i32 2>
124+
; VF4-NEXT: = sext <4 x i32> [[VEC_IND]] to <4 x i64>
125+
126+
; IC2-LABEL: @cast_induction_tail_folding(
127+
; IC2: [[INDEX:%.+]] = phi i32 [ 0, %vector.ph ]
128+
; IC2-NEXT: [[INDEX0:%.+]] = add i32 [[INDEX]], 0
129+
; IC2-NEXT: [[INDEX1:%.+]] = add i32 [[INDEX]], 1
130+
; IC2-NEXT: = icmp ule i32 [[INDEX0]], 2
131+
; IC2-NEXT: = icmp ule i32 [[INDEX1]], 2
132+
;
133+
entry:
134+
br label %loop
135+
136+
loop:
137+
%iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
138+
%iv.ext = sext i32 %iv to i64
139+
%iv.trunc = trunc i64 %iv.ext to i32
140+
%gep = getelementptr inbounds i32, ptr %A, i64 %iv.ext
141+
store i32 %iv.trunc, ptr %gep
142+
%iv.next = add i32 %iv, 1
143+
%c = icmp slt i32 %iv.next, 3
144+
br i1 %c, label %loop, label %exit
145+
146+
exit:
147+
ret void
148+
}

0 commit comments

Comments
 (0)