https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124896

            Bug ID: 124896
           Summary: [SLP][AArch64] Missed vectorization for mixed-type
                    multiplication reduction that Clang handles via NEON
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bug_hunters at yeah dot net
  Target Milestone: ---

**Description:**
GCC fails to auto-vectorize a loop containing a mixed-type multiplication
reduction on AArch64, while Clang successfully vectorizes the same loop using
NEON under identical compilation flags. The loop in question computes product
*= (short)a[i+28] * (short)b[i+28] where a is const unsigned int * and b is
const float *, performing a reduction into a short accumulator. GCC's SLP
vectorizer reports "unsupported SLP instances" and aborts vectorization
entirely, generating purely scalar code. In contrast, Clang successfully
vectorizes the loop with a vectorization width of 8 and an interleaved count of
2, using NEON instructions to load, convert, and multiply 16 elements per
iteration before performing a horizontal reduction. While Clang notes that
scalable vectorization (SVE) is not supported for this reduction pattern, it
gracefully falls back to fixed-width NEON vectorization, demonstrating a more
robust handling of mixed-type multiplication reductions.


**Test case :**
```c
#include <stdint.h>
#include <stddef.h>

long foo(
    const unsigned int * __restrict__ a,
    const float * __restrict__ b,
    int n
) {
    short product = 1;
    for (int i = 0; i < n; i += 1)
    {
        int idx = i;
        product *= (short)a[(idx + 28)];
        product *= (short)b[(idx + 28)];

    }
    return (long)product;
}
```

**gcc version:**
```
aarch64-linux-gnu-gcc (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

**Compilation options:**
```
-O3 -S -march=armv9-a+sve -ftree-vectorize -fopt-info-vec-all
```

**The compiler outputs :**
```
<source>:10:23: missed: couldn't vectorize loop
<source>:10:23: missed: unsupported SLP instances
<source>:4:6: note: vectorized 0 loops in function.
<source>:17:12: note: ***** Analysis failed with vector mode VNx4SI
<source>:17:12: note: ***** Skipping vector mode VNx16QI, which would repeat
the analysis for VNx4SI
```

Also reproducible on Godbolt: https://godbolt.org/z/vPz5sjc4K

**However, Clang vectorizes it.** Clang version 21.1.1.

**clang version:**
```
clang version 21.1.1
Target: unknown
Thread model: posix
Build config: +unoptimized, +assertions
```

**Clang options:**
```
-target aarch64-linux-gnu -march=armv9-a+sve -S -O3 -ftree-vectorize
-ftree-slp-vectorize -Rpass=.*vectorize.* -Rpass-missed=.*vectorize.*
-Rpass-analysis=.*vectorize.*
```

**The result of Clang:**
```
<source>:10:5: remark: Scalable vectorization not supported for the reduction
operations found in this loop. [-Rpass-analysis=loop-vectorize]
   10 |     for (int i = 0; i < n; i += 1)
      |     ^
<source>:10:5: remark: vectorized loop (vectorization width: 8, interleaved
count: 2) [-Rpass=loop-vectorize]
```

Also reproducible on Godbolt: https://godbolt.org/z/6azcTMjo4

Reply via email to