Skip to content

Commit 7700695

Browse files
authored
[VPlan] Fix crash with EVL tail folding intrinsic with no corresponding VP (#121542)
This fixes a crash when building SPEC CPU 2017 with EVL tail folding when widening @llvm.log10 intrinsics. @llvm.log10 and some other intrinsics don't have a corresponding VP intrinsic, so this fixes the crash by removing the assert and bailing instead.
1 parent 3092ebc commit 7700695

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,10 +1498,13 @@ static VPRecipeBase *createEVLRecipe(VPValue *HeaderMask,
14981498
auto *CastR = cast<VPWidenCastRecipe>(CR);
14991499
VPID = VPIntrinsic::getForOpcode(CastR->getOpcode());
15001500
}
1501-
assert(VPID != Intrinsic::not_intrinsic && "Expected VP intrinsic");
1501+
1502+
// Not all intrinsics have a corresponding VP intrinsic.
1503+
if (VPID == Intrinsic::not_intrinsic)
1504+
return nullptr;
15021505
assert(VPIntrinsic::getMaskParamPos(VPID) &&
15031506
VPIntrinsic::getVectorLengthParamPos(VPID) &&
1504-
"Expected VP intrinsic");
1507+
"Expected VP intrinsic to have mask and EVL");
15051508

15061509
SmallVector<VPValue *> Ops(CR->operands());
15071510
Ops.push_back(&AllOneMask);

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-call-intrinsics.ll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,62 @@ exit:
989989
ret void
990990
}
991991

992+
; There's no @llvm.vp.log10, so don't transform it.
993+
define void @log10(ptr %a, ptr %b, i64 %N) {
994+
; IF-EVL-LABEL: define void @log10(
995+
; IF-EVL-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
996+
; IF-EVL-NEXT: [[ENTRY:.*]]:
997+
; IF-EVL-NEXT: br label %[[LOOP:.*]]
998+
; IF-EVL: [[LOOP]]:
999+
; IF-EVL-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ 0, %[[ENTRY]] ]
1000+
; IF-EVL-NEXT: [[GEP:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[IV]]
1001+
; IF-EVL-NEXT: [[TMP0:%.*]] = load float, ptr [[GEP]], align 4
1002+
; IF-EVL-NEXT: [[COND:%.*]] = tail call float @llvm.log10.f32(float [[TMP0]])
1003+
; IF-EVL-NEXT: [[GEP9:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[IV]]
1004+
; IF-EVL-NEXT: store float [[COND]], ptr [[GEP9]], align 4
1005+
; IF-EVL-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
1006+
; IF-EVL-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
1007+
; IF-EVL-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
1008+
; IF-EVL: [[EXIT]]:
1009+
; IF-EVL-NEXT: ret void
1010+
;
1011+
; NO-VP-LABEL: define void @log10(
1012+
; NO-VP-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
1013+
; NO-VP-NEXT: [[ENTRY:.*]]:
1014+
; NO-VP-NEXT: br label %[[LOOP:.*]]
1015+
; NO-VP: [[LOOP]]:
1016+
; NO-VP-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ 0, %[[ENTRY]] ]
1017+
; NO-VP-NEXT: [[GEP:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[IV]]
1018+
; NO-VP-NEXT: [[TMP0:%.*]] = load float, ptr [[GEP]], align 4
1019+
; NO-VP-NEXT: [[COND:%.*]] = tail call float @llvm.log10.f32(float [[TMP0]])
1020+
; NO-VP-NEXT: [[GEP9:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[IV]]
1021+
; NO-VP-NEXT: store float [[COND]], ptr [[GEP9]], align 4
1022+
; NO-VP-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
1023+
; NO-VP-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
1024+
; NO-VP-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
1025+
; NO-VP: [[EXIT]]:
1026+
; NO-VP-NEXT: ret void
1027+
;
1028+
1029+
entry:
1030+
br label %loop
1031+
1032+
loop:
1033+
%iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]
1034+
%gep = getelementptr inbounds float, ptr %b, i64 %iv
1035+
%0 = load float, ptr %gep, align 4
1036+
%cond = tail call float @llvm.log10.f32(float %0)
1037+
%gep9 = getelementptr inbounds float, ptr %a, i64 %iv
1038+
store float %cond, ptr %gep9, align 4
1039+
%iv.next = add nuw nsw i64 %iv, 1
1040+
%exitcond.not = icmp eq i64 %iv.next, %N
1041+
br i1 %exitcond.not, label %exit, label %loop
1042+
1043+
exit:
1044+
ret void
1045+
}
1046+
1047+
9921048
declare i32 @llvm.smax.i32(i32, i32)
9931049
declare i32 @llvm.smin.i32(i32, i32)
9941050
declare i32 @llvm.umax.i32(i32, i32)

0 commit comments

Comments
 (0)