[llvm-bugs] [Bug 51794] New: [LoopVectorizer] Suspected wrong code at -Os

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 8 07:23:00 PDT 2021


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

            Bug ID: 51794
           Summary: [LoopVectorizer]  Suspected wrong code at -Os
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: paulsson at linux.vnet.ibm.com
                CC: llvm-bugs at lists.llvm.org

This program:

int a, d = 0 <= 0;
int *b = &a;
short c = 5;
int main() {
  *b = d;
e:
  --c;
  *b &= b != 0;
  *b ^= -1L;
  if (c)
    goto e;
  printf("%d\n", a);
}

should print '-2', which it does except at -Os when it prints '0' (clang
-march=arch13 -O2 wrong0).

If the loop vectorizer is disabled, -2 is printed also at -Os.

Given that the loop is obviously executed 5 times I suspect that the check
whether to go into the vectorized loop or scalarized loop is wrong at -Os.

At -O2 this check seems correct:

  %c.promoted = load i16, i16* @c, align 2, !tbaa !8
  %2 = add i16 %c.promoted, -1
  %3 = zext i16 %2 to i32
  %4 = add nuw nsw i32 %3, 1
  %min.iters.check = icmp ult i32 %4, 16
  br i1 %min.iters.check, label %scalar.ph, label %vector.ph

This should mean that in this case only the scalar loop is executed.

However at -Os I see this instead:

  %c.promoted = load i16, i16* @c, align 2, !tbaa !8
  %2 = add i16 %c.promoted, -1
  %3 = zext i16 %2 to i32
  %4 = add nuw nsw i32 %3, 1
  br i1 false, label %scalar.ph, label %vector.ph

For some reason the vectorized loop is now always executed, which in this case
should not happen as it will then run more times than intended (at least 16).
This seems strange as the result after iterations are not constant but are
rather toggling and ending up at -2 after exactly 5 iterations, if I am not
mistaken...

-- 
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/20210908/c2209c62/attachment.html>


More information about the llvm-bugs mailing list