[llvm] [LV]Fix max safe elements calculations (PR #122148)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 13:08:10 PST 2025
================
@@ -3943,11 +3943,13 @@ FixedScalableVFPair LoopVectorizationCostModel::computeFeasibleMaxVF(
// It is computed by MaxVF * sizeOf(type) * 8, where type is taken from
// the memory accesses that is most restrictive (involved in the smallest
// dependence distance).
- unsigned MaxSafeElements =
- llvm::bit_floor(Legal->getMaxSafeVectorWidthInBits() / WidestType);
+ unsigned MaxSafeElements = Legal->getMaxSafeVectorWidthInBits() / WidestType;
+ if (Legal->isSafeForAnyVectorWidth())
----------------
alexey-bataev wrote:
No, actually WidestType is always of power of 2. Legal->getMaxSafeVectorWidthInBits() can be non-power-of-2 because of load-store forwarding, if there is non-power-of-2 dependency between loads/stores.
Another problem is that if Legal->isSafeForAnyVectorWidth(), then Legal->getMaxSafeVectorWidthInBits() return UMAX_INT, which is non-power-of (2^64-1), so need to use bit_ceil to avoid some (potential) VF dropping.
https://github.com/llvm/llvm-project/pull/122148
More information about the llvm-commits
mailing list