Skip to content

Commit

Permalink
[SLP]Fix PR89988: do extra analysis of the icmp args to correctly han…
Browse files Browse the repository at this point in the history
…dle signed/unsigned comparison.

If operands of icmp has different signedness, need to consider extending
unsigned operands to correctly handle comparison with the signed
operands.
  • Loading branch information
alexey-bataev committed Apr 25, 2024
1 parent bef6687 commit f758bb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15072,11 +15072,16 @@ void BoUpSLP::computeMinimumValueSizes() {
IsSignedCmp =
NodeIdx < VectorizableTree.size() &&
any_of(VectorizableTree[NodeIdx]->UserTreeIndices,
[](const EdgeInfo &EI) {
[&](const EdgeInfo &EI) {
return EI.UserTE->getOpcode() == Instruction::ICmp &&
any_of(EI.UserTE->Scalars, [](Value *V) {
any_of(EI.UserTE->Scalars, [&](Value *V) {
auto *IC = dyn_cast<ICmpInst>(V);
return IC && IC->isSigned();
return IC &&
(IC->isSigned() ||
!isKnownNonNegative(IC->getOperand(0),
SimplifyQuery(*DL)) ||
!isKnownNonNegative(IC->getOperand(1),
SimplifyQuery(*DL)));
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ define i32 @test(ptr %f, i16 %0) {
; CHECK-NEXT: [[TMP1:%.*]] = load i16, ptr [[F]], align 2
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i16> <i16 0, i16 poison, i16 0, i16 0>, i16 [[TMP0]], i32 1
; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x i16> <i16 0, i16 poison, i16 0, i16 0>, i16 [[TMP1]], i32 1
; CHECK-NEXT: [[TMP4:%.*]] = icmp ule <4 x i16> [[TMP3]], [[TMP2]]
; CHECK-NEXT: [[TMP6:%.*]] = zext <4 x i16> [[TMP3]] to <4 x i32>
; CHECK-NEXT: [[TMP7:%.*]] = sext <4 x i16> [[TMP2]] to <4 x i32>
; CHECK-NEXT: [[TMP4:%.*]] = icmp ule <4 x i32> [[TMP6]], [[TMP7]]
; CHECK-NEXT: [[TMP5:%.*]] = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> [[TMP4]])
; CHECK-NEXT: [[ZEXT_4:%.*]] = zext i1 [[TMP5]] to i32
; CHECK-NEXT: ret i32 [[ZEXT_4]]
Expand Down

0 comments on commit f758bb6

Please sign in to comment.