[llvm] f9c01b5 - [LV] Fix '-1U' bits for smallest type in getSmallestAndWidestTypes (#135783)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 05:26:18 PDT 2025
Author: Sander de Smalen
Date: 2025-04-17T13:26:15+01:00
New Revision: f9c01b59e3d5239a4e42f94d5edbeb3698a81032
URL: https://github.com/llvm/llvm-project/commit/f9c01b59e3d5239a4e42f94d5edbeb3698a81032
DIFF: https://github.com/llvm/llvm-project/commit/f9c01b59e3d5239a4e42f94d5edbeb3698a81032.diff
LOG: [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
https://github.com/llvm/llvm-project/pull/132190#discussion_r2044232607
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/AArch64/smallest-and-widest-types.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d8a510f59a59f..4c1ed15ee700f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4813,17 +4813,16 @@ LoopVectorizationCostModel::getSmallestAndWidestTypes() {
// if there are no loads/stores in the loop. In this case, check through the
// reduction variables to determine the maximum width.
if (ElementTypesInLoop.empty() && !Legal->getReductionVars().empty()) {
- // Reset MaxWidth so that we can find the smallest type used by recurrences
- // in the loop.
- MaxWidth = -1U;
for (const auto &PhiDescriptorPair : Legal->getReductionVars()) {
const RecurrenceDescriptor &RdxDesc = PhiDescriptorPair.second;
// When finding the min width used by the recurrence we need to account
// for casts on the input operands of the recurrence.
- MaxWidth = std::min<unsigned>(
- MaxWidth, std::min<unsigned>(
+ MinWidth = std::min<unsigned>(
+ MinWidth, std::min<unsigned>(
RdxDesc.getMinWidthCastToRecurrenceTypeInBits(),
RdxDesc.getRecurrenceType()->getScalarSizeInBits()));
+ MaxWidth = std::max<unsigned>(
+ MaxWidth, RdxDesc.getRecurrenceType()->getScalarSizeInBits());
}
} else {
for (Type *T : ElementTypesInLoop) {
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/smallest-and-widest-types.ll b/llvm/test/Transforms/LoopVectorize/AArch64/smallest-and-widest-types.ll
index 269562fa70549..b34ba5e38811a 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/smallest-and-widest-types.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/smallest-and-widest-types.ll
@@ -37,7 +37,7 @@ for.end:
; chosen. The following 3 cases check
diff erent combinations of widths.
; CHECK-LABEL: Checking a loop in 'no_loads_stores_32'
-; CHECK: The Smallest and Widest types: 4294967295 / 32 bits
+; CHECK: The Smallest and Widest types: 32 / 64 bits
; CHECK: Selecting VF: 4
define double @no_loads_stores_32(i32 %n) {
@@ -60,7 +60,7 @@ for.end:
}
; CHECK-LABEL: Checking a loop in 'no_loads_stores_16'
-; CHECK: The Smallest and Widest types: 4294967295 / 16 bits
+; CHECK: The Smallest and Widest types: 16 / 64 bits
; CHECK: Selecting VF: 8
define double @no_loads_stores_16() {
@@ -82,7 +82,7 @@ for.end:
}
; CHECK-LABEL: Checking a loop in 'no_loads_stores_8'
-; CHECK: The Smallest and Widest types: 4294967295 / 8 bits
+; CHECK: The Smallest and Widest types: 8 / 32 bits
; CHECK: Selecting VF: 16
define float @no_loads_stores_8() {
More information about the llvm-commits
mailing list