[LoopVectorize] Enable integer Mul and Add as select reduction patterns
authorMatt Devereau <matthew.devereau@arm.com>
Fri, 27 Jan 2023 11:16:07 +0000 (11:16 +0000)
committerMatt Devereau <matthew.devereau@arm.com>
Mon, 30 Jan 2023 09:41:40 +0000 (09:41 +0000)
commit8ff47f6032cbfd49f8fe22d46a48eb602b224661
tree457e0520590d346a2dc8782f52d151d0dfa95c1b
parentbc4326d11a768462d13eb199bba101d1b2a6c18e
[LoopVectorize] Enable integer Mul and Add as select reduction patterns

This patch vectorizes Phi node loop reductions for select's whos condition
comes from a floating-point comparison, with its operands being integers
for Add, Sub, and Mul reductions.

Example:

int foo(float *x, int n) {
    int sum = 0;
    for (int i=0; i<n; ++i) {
        float elem = x[i];
        if (elem > 0) {
            sum += 2;
        }
    }
    return sum;
}

This would previously fail to vectorize due to the integer reduction.
llvm/lib/Analysis/IVDescriptors.cpp
llvm/test/Transforms/LoopVectorize/if-reduction.ll