Skip to content

Commit 3742c2a

Browse files
committed
[SLP]Use stored signedness after minbitwidth analysis.
Need to used stored signedness info for the root node instead of recalculating it after the vectorization, which may lead to a compiler crash.
1 parent 08ce147 commit 3742c2a

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -17476,9 +17476,8 @@ class HorizontalReduction {
1747617476

1747717477
// Emit code to correctly handle reused reduced values, if required.
1747817478
if (OptReusedScalars && !SameScaleFactor) {
17479-
VectorizedRoot =
17480-
emitReusedOps(VectorizedRoot, Builder, V.getRootNodeScalars(),
17481-
SameValuesCounter, TrackedToOrig);
17479+
VectorizedRoot = emitReusedOps(VectorizedRoot, Builder, V,
17480+
SameValuesCounter, TrackedToOrig);
1748217481
}
1748317482

1748417483
Value *ReducedSubTree =
@@ -17818,24 +17817,19 @@ class HorizontalReduction {
1781817817
/// Emits actual operation for the scalar identity values, found during
1781917818
/// horizontal reduction analysis.
1782017819
Value *emitReusedOps(Value *VectorizedValue, IRBuilderBase &Builder,
17821-
ArrayRef<Value *> VL,
17820+
BoUpSLP &R,
1782217821
const MapVector<Value *, unsigned> &SameValuesCounter,
1782317822
const DenseMap<Value *, Value *> &TrackedToOrig) {
1782417823
assert(IsSupportedHorRdxIdentityOp &&
1782517824
"The optimization of matched scalar identity horizontal reductions "
1782617825
"must be supported.");
17826+
ArrayRef<Value *> VL = R.getRootNodeScalars();
1782717827
auto *VTy = cast<FixedVectorType>(VectorizedValue->getType());
1782817828
if (VTy->getElementType() != VL.front()->getType()) {
1782917829
VectorizedValue = Builder.CreateIntCast(
1783017830
VectorizedValue,
1783117831
getWidenedType(VL.front()->getType(), VTy->getNumElements()),
17832-
any_of(VL, [&](Value *R) {
17833-
KnownBits Known = computeKnownBits(
17834-
R, cast<Instruction>(ReductionOps.front().front())
17835-
->getModule()
17836-
->getDataLayout());
17837-
return !Known.isNonNegative();
17838-
}));
17832+
R.isSignedMinBitwidthRootNode());
1783917833
}
1784017834
switch (RdxKind) {
1784117835
case RecurKind::Add: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux < %s | FileCheck %s
3+
4+
define i32 @test() {
5+
; CHECK-LABEL: define i32 @test() {
6+
; CHECK-NEXT: [[ENTRY:.*:]]
7+
; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> zeroinitializer)
8+
; CHECK-NEXT: ret i32 [[TMP0]]
9+
;
10+
entry:
11+
%cond = zext i1 false to i32
12+
%cond258 = zext i1 false to i32
13+
%cond283 = zext i1 false to i32
14+
%cond308 = zext i1 false to i32
15+
%conv685 = or i32 %cond308, %cond
16+
%conv710 = or i32 %conv685, %cond258
17+
%conv735 = or i32 %conv710, %cond283
18+
%conv791 = or i32 %conv735, %cond
19+
ret i32 %conv791
20+
}

0 commit comments

Comments
 (0)