Skip to content

Commit 230b1e8

Browse files
committed
[loop-vectorize] Fix crash when using types that aren't known scale factors
1 parent 3fcd921 commit 230b1e8

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8826,9 +8826,13 @@ bool VPRecipeBuilder::getScaledReductions(
88268826

88278827
PartialReductionChain Chain(RdxExitInstr, ExtA, ExtB, BinOp);
88288828

8829-
unsigned TargetScaleFactor =
8830-
PHI->getType()->getPrimitiveSizeInBits().getKnownScalarFactor(
8831-
A->getType()->getPrimitiveSizeInBits());
8829+
TypeSize PHISize = PHI->getType()->getPrimitiveSizeInBits();
8830+
TypeSize ASize = A->getType()->getPrimitiveSizeInBits();
8831+
8832+
if (!PHISize.hasKnownScalarFactor(ASize))
8833+
return false;
8834+
8835+
unsigned TargetScaleFactor = PHISize.getKnownScalarFactor(ASize);
88328836

88338837
if (LoopVectorizationPlanner::getDecisionAndClampRange(
88348838
[&](ElementCount VF) {

llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-chained.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,28 @@ for.body: ; preds = %for.body.preheader,
10301030
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !loop !1
10311031
}
10321032

1033+
1034+
define void @chained_partial_reduce_not_known_factor(i32 %a, i32 %b, i32 %N) #0 {
1035+
entry:
1036+
br label %for.body
1037+
1038+
for.cond.cleanup:
1039+
%B.0.lcssa = phi i40 [ %2, %for.body ]
1040+
ret void
1041+
1042+
for.body:
1043+
%B.017 = phi i40 [ 0, %entry ], [ %2, %for.body ]
1044+
%i.016 = phi i16 [ 0, %entry ], [ %add21, %for.body ]
1045+
%resize = sext i32 %a to i40
1046+
%resize4 = sext i32 %b to i40
1047+
%0 = or i40 %resize4, %resize
1048+
%1 = or i40 %B.017, %0
1049+
%2 = or i40 %1, 0
1050+
%add21 = add i16 %i.016, 1
1051+
%cmp = icmp slt i16 %i.016, 1
1052+
br i1 %cmp, label %for.body, label %for.cond.cleanup
1053+
}
1054+
10331055
attributes #0 = { vscale_range(1,16) }
10341056

10351057

0 commit comments

Comments
 (0)