[llvm] [LV]Set tailfolding styles before computing feasible max VF. (PR #91403)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Mon May 13 06:13:15 PDT 2024


alexey-bataev wrote:

> Is this just the refactoring to move the point where tail-folding styles are computed? I might have missed this, but can the test changes be avoided?

I hoped to make it a refactoring, but unfortunately, it is not. Looks like there is a bug in the current implementation of the loop vectorizer. When calling Legal->prepareToFoldTailByMasking(), it fills LoopVectorizationLegality::MaskedOp, which is later used in Legal->isMaskRequired() to check if the instruction requires masking. But if after Legal->prepareToFoldTailByMasking() the compiler decides to turn off tail folding, it does not clear LoopVectorizationLegality::MaskedOp and still uses this data. It leads to incorrect cost modeling. Instead of Legal->isMaskRequired() the pass should use LoopVectorizationCostModel::isPredicatedInst(), which checks that tail folding is enabled before checking for Legal->isMaskRequired(). But it causes the changes in the tests, which are pass Legal->prepareToFoldTailByMasking() check, but later disable tail folding for some reason (say, using the option).

https://github.com/llvm/llvm-project/pull/91403


More information about the llvm-commits mailing list