[llvm-bugs] [Bug 36889] New: [MachineLICM] wrong code

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 24 09:59:36 PDT 2018


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

            Bug ID: 36889
           Summary: [MachineLICM]  wrong code
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: paulsson at linux.vnet.ibm.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20117
  --> https://bugs.llvm.org/attachment.cgi?id=20117&action=edit
reduced testcase (llc input)

It seems that "Re-commit: [MachineLICM] Add functions to MachineLICM to hoist
invariant stores" (4561f7d / r328326) is causing failures in internal test-runs
on SystemZ (CSmith).

I have reduced such a test case with creduce and analyzed it to a point where I
can see the error. It is clear to me that an illegal hoisting of a store has
been made, and the unreduced test case passes if I revert the commit.

Program:

a[6];
b = 15, c, d, e = -1L, f, h;
*g = &f;
main() {
  for (; c < 6; c++)
    a[1] = c;
  int i = 14;
  for (; d >= 0; d--) {
    for (; e <= 0; e++)
      *g = i;
    int j = &i;
    h = j;
    i = 0;
    b = a[b ^ f];
  }
  printf("checksum = %X\n", b);
}

The correct checksum is 5. With MachineLICM 0 is instead printed.

- a[1] becomes 5 in the first loop.
- b is initialized to 15.
- *g points to f, and gets value 14 in innermost loop.
- b ^ f (15 ^ 14) is 1, so b gets a[1], which is 5.

The incorrect LICM transformation is to move out the 'i = 0;' statement. If
that is made before the loop, then *g gets value 0 instead, and b ^ f does not
become 1.

Debug output:

Hoisting MVHI %stack.0.i, 0, 0 :: (store 4 into %ir.i, !tbaa !2)

Run line: bin/llc -mcpu=z13 -O3 wrong1.ll -o out.s

-- 
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/20180324/70ff1b8b/attachment.html>


More information about the llvm-bugs mailing list