[llvm-bugs] [Bug 47895] New: Unnecessary load not eliminated

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Oct 18 14:15:14 PDT 2020


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

            Bug ID: 47895
           Summary: Unnecessary load not eliminated
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

Extracted from PR47887


Testcase:
void foo(int *p,int *q,int x) {
  *p=x;
  *q=x;
  if(*p!=x)  /* false */
    __builtin_abort();
}

Clang -O3:
foo(int*, int*, int):                            # @foo(int*, int*, int)
        push    rax
        mov     dword ptr [rdi], edx
        mov     dword ptr [rsi], edx
        cmp     dword ptr [rdi], edx
        jne     .LBB0_2
        pop     rax
        ret
.LBB0_2:
        call    abort

GCC can remove unnecessary load.
foo(int*, int*, int):
        mov     DWORD PTR [rdi], edx
        mov     DWORD PTR [rsi], edx
        ret


Analysis of the problem by Florian Hahn (thx!):
"In the case above neither of the stores is dead. The load is unnecessary, but
only because we store the same value to both p and q. `store i32 x, i32* q` may
alias `load p`, but it stores the same value as the store to p. 

We should be able to handle this with MemorySSA, possibly as an extension of
DSE, but it won't fit directly in the main elimination loop and will need some
extra code."

-- 
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/20201018/f260ec3b/attachment-0001.html>


More information about the llvm-bugs mailing list