Skip to content

Commit 913dcf1

Browse files
committed
[SLP]Fix type promotion for smax reduction with unsigned reduced operands
Need to add an extra bit for sign info for unsigned reduced values to generate correct code.
1 parent 81739c3 commit 913dcf1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20521,7 +20521,8 @@ void BoUpSLP::computeMinimumValueSizes() {
2052120521
}
2052220522
bool IsSignedCmp = false;
2052320523
if (UserIgnoreList && all_of(*UserIgnoreList, [](Value *V) {
20524-
return match(V, m_SMin(m_Value(), m_Value()));
20524+
return match(V, m_SMin(m_Value(), m_Value())) ||
20525+
match(V, m_SMax(m_Value(), m_Value()));
2052520526
}))
2052620527
IsSignedCmp = true;
2052720528
while (NodeIdx < VectorizableTree.size()) {

llvm/test/Transforms/SLPVectorizer/RISCV/smax-reduction-unsigned-missing-sign.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ define i32 @test(i8 %0) {
77
; CHECK-NEXT: [[ENTRY:.*:]]
88
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x i8> <i8 poison, i8 0, i8 0, i8 0>, i8 [[TMP0]], i32 0
99
; CHECK-NEXT: [[TMP2:%.*]] = icmp ne <4 x i8> [[TMP1]], zeroinitializer
10-
; CHECK-NEXT: [[TMP3:%.*]] = call i1 @llvm.vector.reduce.smax.v4i1(<4 x i1> [[TMP2]])
11-
; CHECK-NEXT: [[TMP4:%.*]] = zext i1 [[TMP3]] to i32
10+
; CHECK-NEXT: [[TMP3:%.*]] = zext <4 x i1> [[TMP2]] to <4 x i8>
11+
; CHECK-NEXT: [[TMP5:%.*]] = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> [[TMP3]])
12+
; CHECK-NEXT: [[TMP4:%.*]] = zext i8 [[TMP5]] to i32
1213
; CHECK-NEXT: ret i32 [[TMP4]]
1314
;
1415
entry:

0 commit comments

Comments
 (0)