Alias analysis confused by loop
| Bugzilla Link | 12567 |
| Resolution | DUPLICATE |
| Resolved on | Jul 26, 2012 15:14 |
| Version | trunk |
| OS | Linux |
| Attachments | test file that shows the problem |
| CC | @asl |
Extended Description
Compile the attached file with: clang -O3 -S test_alias.c
When p_a, p_b and p_c are initialized outside the loop, llvm is not able to deduce that p_a, p_b and p_c will not alias. Because of that it will keep the writes to '*p_c', resulting in slower code.
Note: If the initialization is done inside the loop, everything is fine. Note: gcc is able to deduce that these will not alias in both cases.
Code that clang/llvm produces:
... .file "test_alias_002.c" .text .globl foo_002 .align 16, 0x90 .type foo_002,@function foo_002: # @foo_002 .cfi_startproc
BB#0: # %entry
xorl %eax, %eax
.align 16, 0x90
.LBB0_1: # %for.body # =>This Inner Loop Header: Depth=1 movl $0, c(%rax) movl b(,%rax,4), %ecx imull a(,%rax,4), %ecx movl %ecx, c(%rax) #### Unnecessary store movl b+4(,%rax,4), %edx imull a+4(,%rax,4), %edx addl %ecx, %edx leaq 4(%rax), %rcx movl %edx, c(%rax) #### Unnecessary store movl b+8(,%rax,4), %esi imull a+8(,%rax,4), %esi addl %edx, %esi movl %esi, c(%rax) #### Unnecessary store movl b+12(,%rax,4), %edx imull a+12(,%rax,4), %edx addl %esi, %edx cmpl $128, %ecx movl %edx, c(%rax) movq %rcx, %rax jne .LBB0_1
BB#2: # %for.end
ret
.Ltmp0:
...
*** This bug has been marked as a duplicate of bug llvm/llvm-project#11703 ***