[llvm-bugs] [Bug 48546] New: [LoopVectorization] Invalid code after interleaving add reduction

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 17 11:18:41 PST 2020


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

            Bug ID: 48546
           Summary: [LoopVectorization] Invalid code after interleaving
                    add reduction
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: congzhecao at gmail.com
                CC: llvm-bugs at lists.llvm.org

The following C code generate an issue as follows:

int printf(const char *, ...);
int a, b, e;
char c, d;
int main() {
  d = 19;
  for (; d < 45; d++) {
    char *f = &c;
    *f &= 1;
    e = b== 0 ?:a%b;
    (*f)--;
  }
  printf("%d\n", c);
}

This code compiled with the following flag causes a bug:

clang test.c -O2 && ./a.out
Output: 254

The correct output is '0'.

Upon further investigation, the bug is caused by the interleaving of the Loop
Vectorizer.

The follwing command produces correct code:

clang test.c -O2 -mllvm -force-vector-interleave=1 && ./a.out

The root cause is not clear yet, but it seems like there is an add reduction
that the loop vectorization legalily determines that it is safe to vectorize,
but in this case it generates an incorrect result.

The IVDescriptor.cpp:629, the function call to AddReductionVar for Add
reduction finds this to be a signed i1 add reduction, which to me seems like an
invalid type.

The test file reduction-small-size.ll is important for this because it has the
same type if reduction, but the interleaving is forced to 1, if we force it to
2 we have an invalid code.

-- 
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/20201217/cf142e1e/attachment.html>


More information about the llvm-bugs mailing list