Skip to content

Commit bdf21ca

Browse files
authored
[LV] Fix missing entry in willGenerateVectors (#136712)
willGenerateVectors switches on opcodes of a recipe, but Histogram is missing in the switch statement, which could cause a crash in some cases. The crash was initially observed when developing another patch.
1 parent 213424b commit bdf21ca

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,6 +4460,7 @@ static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
44604460
case VPDef::VPWidenSelectSC:
44614461
case VPDef::VPBlendSC:
44624462
case VPDef::VPFirstOrderRecurrencePHISC:
4463+
case VPDef::VPHistogramSC:
44634464
case VPDef::VPWidenPHISC:
44644465
case VPDef::VPWidenIntOrFpInductionSC:
44654466
case VPDef::VPWidenPointerInductionSC:

llvm/test/Transforms/LoopVectorize/AArch64/sve2-histcnt.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,48 @@ for.exit:
753753
ret void
754754
}
755755

756+
; The histogram operation generates vectors. This example used to crash
757+
; due to a missing entry in a switch statement.
758+
define void @histogram_generates_vectors_crash(ptr %data_array, ptr noalias %indices) {
759+
; CHECK-LABEL: define void @histogram_generates_vectors_crash(
760+
; CHECK-SAME: ptr [[DATA_ARRAY:%.*]], ptr noalias [[INDICES:%.*]]) {
761+
; CHECK-NEXT: entry:
762+
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
763+
; CHECK: for.body:
764+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
765+
; CHECK-NEXT: [[GEP_INDICES:%.*]] = getelementptr [1048576 x i32], ptr [[INDICES]], i64 [[IV]]
766+
; CHECK-NEXT: [[L_IDX:%.*]] = load i32, ptr [[GEP_INDICES]], align 4
767+
; CHECK-NEXT: [[IDXPROM5:%.*]] = sext i32 [[L_IDX]] to i64
768+
; CHECK-NEXT: [[GEP_BUCKET:%.*]] = getelementptr [1048576 x i32], ptr [[DATA_ARRAY]], i64 [[IDXPROM5]]
769+
; CHECK-NEXT: [[L_BUCKET:%.*]] = load i32, ptr [[GEP_BUCKET]], align 4
770+
; CHECK-NEXT: [[INC:%.*]] = add i32 [[L_BUCKET]], 1
771+
; CHECK-NEXT: store i32 [[INC]], ptr [[GEP_BUCKET]], align 4
772+
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
773+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 1
774+
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_EXIT:%.*]], label [[FOR_BODY]]
775+
; CHECK: for.exit:
776+
; CHECK-NEXT: ret void
777+
;
778+
entry:
779+
br label %for.body
780+
781+
for.body:
782+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
783+
%gep.indices = getelementptr [1048576 x i32], ptr %indices, i64 %iv
784+
%l.idx = load i32, ptr %gep.indices, align 4
785+
%idxprom5 = sext i32 %l.idx to i64
786+
%gep.bucket = getelementptr [1048576 x i32], ptr %data_array, i64 %idxprom5
787+
%l.bucket = load i32, ptr %gep.bucket, align 4
788+
%inc = add i32 %l.bucket, 1
789+
store i32 %inc, ptr %gep.bucket, align 4
790+
%iv.next = add i64 %iv, 1
791+
%exitcond = icmp eq i64 %iv, 1
792+
br i1 %exitcond, label %for.exit, label %for.body
793+
794+
for.exit:
795+
ret void
796+
}
797+
756798
attributes #0 = { "target-features"="+sve2" vscale_range(1,16) }
757799

758800
!0 = distinct !{!0, !1}

0 commit comments

Comments
 (0)