[LLVMbugs] [Bug 20585] New: TBAA enhancement to hoist/sink global variable out of loop

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 7 22:05:19 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20585

            Bug ID: 20585
           Summary: TBAA enhancement to hoist/sink global variable out of
                    loop
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Global Analyses
          Assignee: unassignedbugs at nondot.org
          Reporter: liujiangning1 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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, at 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, at object               // @i
    .comm    i,4,4
    .type    ps, at 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.

-- 
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/20140808/1275bac6/attachment.html>


More information about the llvm-bugs mailing list