Skip to content

Commit

Permalink
[SLP]Use stored signedness after minbitwidth analysis.
Browse files Browse the repository at this point in the history
Need to used stored signedness info for the root node instead of
recalculating it after the vectorization, which may lead to a compiler
crash.
  • Loading branch information
alexey-bataev committed Jul 10, 2024
1 parent 08ce147 commit 3742c2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
16 changes: 5 additions & 11 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17476,9 +17476,8 @@ class HorizontalReduction {

// Emit code to correctly handle reused reduced values, if required.
if (OptReusedScalars && !SameScaleFactor) {
VectorizedRoot =
emitReusedOps(VectorizedRoot, Builder, V.getRootNodeScalars(),
SameValuesCounter, TrackedToOrig);
VectorizedRoot = emitReusedOps(VectorizedRoot, Builder, V,
SameValuesCounter, TrackedToOrig);
}

Value *ReducedSubTree =
Expand Down Expand Up @@ -17818,24 +17817,19 @@ class HorizontalReduction {
/// Emits actual operation for the scalar identity values, found during
/// horizontal reduction analysis.
Value *emitReusedOps(Value *VectorizedValue, IRBuilderBase &Builder,
ArrayRef<Value *> VL,
BoUpSLP &R,
const MapVector<Value *, unsigned> &SameValuesCounter,
const DenseMap<Value *, Value *> &TrackedToOrig) {
assert(IsSupportedHorRdxIdentityOp &&
"The optimization of matched scalar identity horizontal reductions "
"must be supported.");
ArrayRef<Value *> VL = R.getRootNodeScalars();
auto *VTy = cast<FixedVectorType>(VectorizedValue->getType());
if (VTy->getElementType() != VL.front()->getType()) {
VectorizedValue = Builder.CreateIntCast(
VectorizedValue,
getWidenedType(VL.front()->getType(), VTy->getNumElements()),
any_of(VL, [&](Value *R) {
KnownBits Known = computeKnownBits(
R, cast<Instruction>(ReductionOps.front().front())
->getModule()
->getDataLayout());
return !Known.isNonNegative();
}));
R.isSignedMinBitwidthRootNode());
}
switch (RdxKind) {
case RecurKind::Add: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux < %s | FileCheck %s

define i32 @test() {
; CHECK-LABEL: define i32 @test() {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> zeroinitializer)
; CHECK-NEXT: ret i32 [[TMP0]]
;
entry:
%cond = zext i1 false to i32
%cond258 = zext i1 false to i32
%cond283 = zext i1 false to i32
%cond308 = zext i1 false to i32
%conv685 = or i32 %cond308, %cond
%conv710 = or i32 %conv685, %cond258
%conv735 = or i32 %conv710, %cond283
%conv791 = or i32 %conv735, %cond
ret i32 %conv791
}

0 comments on commit 3742c2a

Please sign in to comment.