[llvm-bugs] [Bug 47371] New: Loop Vectorizer Generates Unreachable Fast Path

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 31 12:52:45 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47371

            Bug ID: 47371
           Summary: Loop Vectorizer Generates Unreachable Fast Path
           Product: tools
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: llc
          Assignee: unassignedbugs at nondot.org
          Reporter: thoren.paulson at gmail.com
                CC: llvm-bugs at lists.llvm.org

Overview:
I found a simple example that the loop vectorizer tries to optimize, but
generates vector code that's unreachable due to contradicting conditions.

Steps to Reproduce:
C++ Example, compiled with `clang -O2` targeting x86_64, see
https://godbolt.org/z/5x9WTb

```
#include <cstddef>

void pan(float* samples, size_t len, float coef) {
    float c[4] = { 1.0f - coef, coef, 1.0f - coef, coef };

    for (size_t i = 0; i < len; i++) {
        samples[i] *= c[i % 4];
    }
}
```

Actual results:
See https://godbolt.org/z/5x9WTb or compile the example for assembly output,
but here's the part that seems contradictory:

```
test    rsi, rsi
je      .LBB0_14       # jump if len == 0
xor     eax, eax
cmp     rsi, 8
jb      .LBB0_3        # jump if len < 8
lea     rcx, [rsi - 1]
cmp     rcx, 4
jae     .LBB0_3        # jump if len >= 5
```

`.LBB0_3` is the non-vectorized clean up path, and `rsi` hold `len`. This code
will always go to the cleanup loop instead of falling through to the vectorized
code, since `len` cannot be greater than 8 but less than 5.

Expected results:
Any `len` greater than 8 (or some other appropriate value) should execute the
`mulps` instructions until the remainder is less than the vectorization width.


Additional information:
I originally discovered this in Rust in this form: https://godbolt.org/z/6M7Pon
This leads me to believe its a backend issue and not clang and rustc.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200831/4ee4d1c7/attachment.html>


More information about the llvm-bugs mailing list