Skip to content

Commit f9c01b5

Browse files
[LV] Fix '-1U' bits for smallest type in getSmallestAndWidestTypes (#135783)
For loops without loads/stores, where the smallest/widest types are calculated from the reduction, the smallest type returned is always -1U and it actually returns the smallest type as the widest type. This PR fixes the calculation. This follows from #132190 (comment)
1 parent f135ce6 commit f9c01b5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -4813,17 +4813,16 @@ LoopVectorizationCostModel::getSmallestAndWidestTypes() {
48134813
// if there are no loads/stores in the loop. In this case, check through the
48144814
// reduction variables to determine the maximum width.
48154815
if (ElementTypesInLoop.empty() && !Legal->getReductionVars().empty()) {
4816-
// Reset MaxWidth so that we can find the smallest type used by recurrences
4817-
// in the loop.
4818-
MaxWidth = -1U;
48194816
for (const auto &PhiDescriptorPair : Legal->getReductionVars()) {
48204817
const RecurrenceDescriptor &RdxDesc = PhiDescriptorPair.second;
48214818
// When finding the min width used by the recurrence we need to account
48224819
// for casts on the input operands of the recurrence.
4823-
MaxWidth = std::min<unsigned>(
4824-
MaxWidth, std::min<unsigned>(
4820+
MinWidth = std::min<unsigned>(
4821+
MinWidth, std::min<unsigned>(
48254822
RdxDesc.getMinWidthCastToRecurrenceTypeInBits(),
48264823
RdxDesc.getRecurrenceType()->getScalarSizeInBits()));
4824+
MaxWidth = std::max<unsigned>(
4825+
MaxWidth, RdxDesc.getRecurrenceType()->getScalarSizeInBits());
48274826
}
48284827
} else {
48294828
for (Type *T : ElementTypesInLoop) {

llvm/test/Transforms/LoopVectorize/AArch64/smallest-and-widest-types.ll

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ for.end:
3737
; chosen. The following 3 cases check different combinations of widths.
3838

3939
; CHECK-LABEL: Checking a loop in 'no_loads_stores_32'
40-
; CHECK: The Smallest and Widest types: 4294967295 / 32 bits
40+
; CHECK: The Smallest and Widest types: 32 / 64 bits
4141
; CHECK: Selecting VF: 4
4242

4343
define double @no_loads_stores_32(i32 %n) {
@@ -60,7 +60,7 @@ for.end:
6060
}
6161

6262
; CHECK-LABEL: Checking a loop in 'no_loads_stores_16'
63-
; CHECK: The Smallest and Widest types: 4294967295 / 16 bits
63+
; CHECK: The Smallest and Widest types: 16 / 64 bits
6464
; CHECK: Selecting VF: 8
6565

6666
define double @no_loads_stores_16() {
@@ -82,7 +82,7 @@ for.end:
8282
}
8383

8484
; CHECK-LABEL: Checking a loop in 'no_loads_stores_8'
85-
; CHECK: The Smallest and Widest types: 4294967295 / 8 bits
85+
; CHECK: The Smallest and Widest types: 8 / 32 bits
8686
; CHECK: Selecting VF: 16
8787

8888
define float @no_loads_stores_8() {

0 commit comments

Comments
 (0)