<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - TBAA enhancement to hoist/sink global variable out of loop"
   href="http://llvm.org/bugs/show_bug.cgi?id=20585">20585</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>TBAA enhancement to hoist/sink global variable out of loop
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Global Analyses
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>liujiangning1@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Currently TBAA can't return NoAlias as exposed by the following case.

{code}
$ cat alias.c 
typedef struct {int x; int y;} S;
S **ps;
int i;
main()
{
  do {
    ps[i]->x = i;
    i++;
  } while (i);
}
$ ~/llvm/build/bin/clang --target=aarch64-linux-gnuabi alias.c -S -O2
alias.c:4:1: warning: type specifier missing, defaults to 'int'
[-Wimplicit-int]
main()
^
1 warning generated.
$ cat alias.s
    .text
    .file    "alias.c"
    .globl    main
    .align    2
    .type    main,@function
main:                                   // @main
// BB#0:                                // %entry
    adrp    x9, ps
    adrp    x8, i
    ldr    x9, [x9, :lo12:ps]
    ldr    w10, [x8, :lo12:i]
.LBB0_1:                                // %do.body
                                        // =>This Inner Loop Header: Depth=1
    ldr    x11, [x9, w10, sxtw #3]
    str     w10, [x11]
    ldr    w10, [x8, :lo12:i]    // inside the loop
    add    w10, w10, #1            // =1
    str    w10, [x8, :lo12:i]    // inside the loop 
    cbnz    w10, .LBB0_1
// BB#2:                                // %do.end
    mov     w0, wzr
    ret
.Ltmp1:
    .size    main, .Ltmp1-main

    .type    i,@object               // @i
    .comm    i,4,4
    .type    ps,@object              // @ps
    .comm    ps,8,8

    .ident    "clang version 3.6.0 "
$ aarch64-linux-gnu-gcc alias.c -S -O2
$ cat alias.s
    .cpu generic
    .file    "alias.c"
    .section    .text.startup,"ax",%progbits
    .align    2
    .global    main
    .type    main, %function
main:
    adrp    x4, i
    adrp    x1, ps
    ldr    w0, [x4,#:lo12:i]  // hoisted out loop
    ldr    x1, [x1,#:lo12:ps]
    add    x1, x1, x0, sxtw 3
    b    .L3
.L5:
    mov    w0, w2
.L3:
    ldr    x3, [x1],8
    adds    w2, w0, 1
    str    w0, [x3]
    bne    .L5
    str    w2, [x4,#:lo12:i]  // sink out of loop
    ret
    .size    main, .-main
    .comm    i,4,4
    .comm    ps,8,8
    .ident    "GCC: (Ubuntu/Linaro 4.8.1-10ubuntu7) 4.8.1"
{code}

For this case, gcc can hoist/sink load/store out of loop, but llvm can't. "gcc
-fno-strict-aliasing" will also fail to hoist/sink load/store out of loop. GCC
enabled -strict-aliasing by default, but it seems LLVM doesn't support it so
far.

This feature can improve benchmark performance a lot, and for even one of
spec2000 benchmarks, we can see ~6% performance improvement.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>