[LLVMbugs] [Bug 8572] New: Incomplete type based aliasing support

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 9 00:10:14 PST 2010


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

           Summary: Incomplete type based aliasing support
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: quality-of-implementation
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: xinliangli at gmail.com
                CC: llvmbugs at cs.uiuc.edu, xinliangli at gmail.com


This is probably a known limitation as the tbaa support is unfinished.

Test case:


truct BUF1
{
  int b1; 
  int b12;
};

struct BUF2
{
  int b2; 
  int g;
};


int foo(int n, struct BUF1* p, struct BUF2* q)
{
    int i = 0;
    for (i = 0; i < n; i++)
    {   
        p->b1 += q->b2;
    }   
    return 0;
}


// gcc -O2 generates:


 6 foo:
  7 .LFB0:
  8         .cfi_startproc
  9         testl   %edi, %edi
 10         jle     .L2
 11         movl    (%rdx), %eax
 12         decl    %edi
 13         movl    (%rsi), %edx
 14         imull   %eax, %edi
 15         addl    %eax, %edx
 16         addl    %edx, %edi
 17         movl    %edi, (%rsi)
 18 .L2:
 19         xorl    %eax, %eax
 20         ret


// clang -O2 -fomit-frame-pointer -mllvm -enable-tbaa generates:


 6 foo:
  7 .Leh_func_begin0:
  8         testl   %edi, %edi
  9         jle     .LBB0_3
 10         movl    (%rsi), %eax
 11         .align  16, 0x90
 12 .LBB0_2:
 13         addl    (%rdx), %eax
 14         movl    %eax, (%rsi)
 15         decl    %edi
 16         jne     .LBB0_2
 17 .LBB0_3:
 18         xorl    %eax, %eax
 19         ret


Gcc flattens the loop and folds the computation, but llvm keeps the loop with
load and store.

Note for simple scalar type, llvm works fine.

Example from SPEC06 libquantum:

1 typedef struct quantum_reg_node_struct {
  2    int state;
  3 } quantum_reg_node;
  4 
  5 typedef struct quantum_reg_struct {
  6    int size; quantum_reg_node* node;
  7 } quantum_reg;
  8 
  9 void foo( quantum_reg* reg,int target)
 10 {
 11    int i;
 12    for (i = 0 ; i < reg->size; i++)
 13    {
 14       reg->node[i].state^= (1<< target);
 15    }
 16 }

The load of reg->size and reg->node should be hoisted out of the loop.

Loop from gcc:

19 .L3:
 20         xorl    %edx, (%rax,%rcx,4)
 21         incq    %rcx
 22         cmpl    %ecx, %r8d
 23         jg      .L3

Loop from clang/llvm:

16 .LBB0_2:
 17         xorl    %eax, (%rcx,%rdx,4)
 18         incq    %rdx
 19         cmpl    (%rdi), %edx          <--- extra load
 20         jl      .LBB0_2


David

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list