In the LoopVectorize pass, when the -prefer-inloop-reductions flag is enabled and the reduction instruction is the intrinsic smax, the flag does not function correctly, resulting in reductions being performed outside the loop.
More Explanation:
In the function RecurrenceDescriptor::getReductionOpChain in IVDescriptors.cpp, the code only looks for select or compare instructions. If the compare instruction is replaced with the intrinsic smax before the vectorizer runs, isCorrectOpcode returns false, causing the reduction to be handled incorrectly.
However, if you block the function in InstCombinePass that canonicalizes SPG to min/max, allowing the compare/select instructions to remain, the reduction works correctly and is performed within the loop.
In the LoopVectorize pass, when the -prefer-inloop-reductions flag is enabled and the reduction instruction is the intrinsic smax, the flag does not function correctly, resulting in reductions being performed outside the loop.
Producer: Godbolt Example
More Explanation: In the function RecurrenceDescriptor::getReductionOpChain in IVDescriptors.cpp, the code only looks for select or compare instructions. If the compare instruction is replaced with the intrinsic smax before the vectorizer runs, isCorrectOpcode returns false, causing the reduction to be handled incorrectly.
However, if you block the function in InstCombinePass that canonicalizes SPG to min/max, allowing the compare/select instructions to remain, the reduction works correctly and is performed within the loop.