[llvm] [LV] Header masked condition of FindLastSelect when optimizeFindIVReductions when folding tail. (PR #191166)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 12:53:18 PDT 2026


https://github.com/fhahn approved this pull request.

LGTM, thanks.

Given that it's almost the weekend, I hope you don't mind me merging the patch.

There are still some cases not handled correctly in the latest version, 


> Wouldn't @lukel97 's [main...lukel97:llvm-project:loop-vectorize/move-tailfolding-reductionphis](https://github.com/llvm/llvm-project/compare/main...lukel97:llvm-project:loop-vectorize/move-tailfolding-reductionphis) be a better fix? Or am I misunderstanding the issue?
> 
> For the newly added test with current trunk: https://godbolt.org/z/YK64fccK3, IMO `foldTailByMasking` is where the problem "originates". We've also have touched this before, I think: [#176143 (comment)](https://github.com/llvm/llvm-project/pull/176143#discussion_r2770230945)

IIUC this would just change where we create selects for the reduction when tail-folding, which would still happen before the optimizations here, so I think the transformations would still need to handle those selects properly.

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


More information about the llvm-commits mailing list