Skip to content

Commit cff6652

Browse files
committed
[VPlan] Handle VPValues without underlying values in getTypeForVPValue.
Fixes a crash after 0c8e5be. Full type inference will be added in #69013
1 parent 8e0b3a8 commit cff6652

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ static Type *getTypeForVPValue(VPValue *VPV) {
827827
if (auto *VPC = dyn_cast<VPWidenCastRecipe>(VPV))
828828
return VPC->getResultType();
829829
auto *UV = VPV->getUnderlyingValue();
830-
return UV->getType();
830+
return UV ? UV->getType() : nullptr;
831831
}
832832

833833
/// Try to simplify recipe \p R.
@@ -848,7 +848,8 @@ static void simplifyRecipe(VPRecipeBase &R) {
848848
break;
849849
VPValue *A = Zext->getOperand(0);
850850
VPValue *Trunc = R.getVPSingleValue();
851-
if (getTypeForVPValue(Trunc) == getTypeForVPValue(A))
851+
Type *TruncToTy = getTypeForVPValue(Trunc);
852+
if (TruncToTy && TruncToTy == getTypeForVPValue(A))
852853
Trunc->replaceAllUsesWith(A);
853854
break;
854855
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,40 @@ exit:
4040
ret void
4141
}
4242

43+
define void @redundant_iv_cast(ptr %dst) {
44+
; VF4-LABEL: @redundant_iv_cast
45+
; VF4: vector.body:
46+
; VF4: [[VEC_IND:%.+]] = phi <4 x i16> [ <i16 0, i16 1, i16 2, i16 3>, %vector.ph ], [ [[VEC_IND_NEXT:%.+]], %vector.body ]
47+
; VF4: store <4 x i16> [[VEC_IND]]
48+
; VF4: [[VEC_IND_NEXT]] = add <4 x i16> [[VEC_IND]], <i16 4, i16 4, i16 4, i16 4>
49+
;
50+
; IC2-LABEL: @redundant_iv_cast
51+
; IC2: vector.body:
52+
; IC2-NEXT: [[CAN_IV:%.+]] = phi i32 [ 0, %vector.ph ], [ [[CAN_IV_NEXT:%.+]], %vector.body ]
53+
; IC2-NEXT: [[OFFSET_IDX:%.+]] = trunc i32 [[CAN_IV]] to i16
54+
; IC2-NEXT: [[P0:%.+]] = add i16 [[OFFSET_IDX]], 0
55+
; IC2-NEXT: [[P1:%.+]] = add i16 [[OFFSET_IDX]], 1
56+
; IC2-NEXT: [[Z0:%.+]] = zext i16 [[P0]] to i32
57+
; IC2-NEXT: [[Z1:%.+]] = zext i16 [[P1]] to i32
58+
; IC2-NEXT: [[T0:%.+]] = trunc i32 [[Z0]] to i16
59+
; IC2-NEXT: [[T1:%.+]] = trunc i32 [[Z1]] to i16
60+
; IC2: store i16 [[T0]]
61+
; IC2-NEXT: store i16 [[T1]]
62+
;
63+
entry:
64+
br label %loop
65+
66+
loop:
67+
%j.0 = phi i16 [ 0, %entry ], [ %inc, %loop ]
68+
%ext = zext i16 %j.0 to i32
69+
%trunc = trunc i32 %ext to i16
70+
%gep = getelementptr inbounds i16, ptr %dst, i16 %j.0
71+
store i16 %trunc, ptr %gep
72+
%0 = icmp eq i16 10000, %j.0
73+
%inc = add i16 %j.0, 1
74+
br i1 %0, label %exit, label %loop
75+
76+
77+
exit:
78+
ret void
79+
}

0 commit comments

Comments
 (0)