[llvm-bugs] [Bug 43166] New: LoopVectorizer miscompiles (when doing fold by tail masking?)

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 29 07:28:27 PDT 2019


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

            Bug ID: 43166
           Summary: LoopVectorizer miscompiles (when doing fold by tail
                    masking?)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: bjorn.a.pettersson at ericsson.com
                CC: ayal.zaks at intel.com, llvm-bugs at lists.llvm.org

Created attachment 22447
  --> https://bugs.llvm.org/attachment.cgi?id=22447&action=edit
A somewhat reduced ll test case

A test case (lv-bug.c) like this seems to miscompile when using -fvectorize:

  #include <stdint.h>
  #include <stdio.h>

  int y = 0;
  int b = 1;
  int d = 1;

  int main() {
    #pragma clang loop vectorize_width(4)
    for (int i = 0; i < 3; ++i) {
      b = (y == 0) ? d : (d / y);
    }
    if (b == 1)
      printf("GOOD!\n");
    else
      printf("BAD!\n");
  }


When compiled+executed (for x86_64 GNU/Linux) using

    build-all/bin/clang -O1 lv-bug.c && ./a.out

the result is "GOOD!"

When compiled+executed using

    build-all/bin/clang -O1 lv-bug.c -fvectorize && ./a.out

the result is "BAD!"


Also see comments in the attached lv-fold-tail-by-masking-bug.ll lit test case.

Afaict the problem is related to the "fold tail by masking" that takes place
(since we have a small trip count that even is smaller than the VF, but the
problem is also seen if we for example increase the trip count to 9).

Somehow the presence of the conditional sdiv (not executed for y==0) inside the
loop fools LV to vectorize the loop???
(if changing the sdiv to for example xor I see remarks such as "loop not
vectorized: Cannot fold tail by masking in the presence of live outs.")

I've tried lots of old (nightly) downstream builds of clang, and it started to
fail around October 2018. So I do not think that it is a new bug.
The ll-reproducer indicates that the problem exist in opt 8.0.0 (when testing
on https://godbolt.org/z/uaz-P9).

-- 
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/20190829/714ee488/attachment.html>


More information about the llvm-bugs mailing list