[llvm-bugs] [Bug 45737] New: Failure to remove useless reload

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 29 08:59:12 PDT 2020


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

            Bug ID: 45737
           Summary: Failure to remove useless reload
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: gabravier at gmail.com
                CC: llvm-bugs at lists.llvm.org

struct testStruct
{
    struct testStruct* p1;
    struct testStruct* p2;
};

void f(struct testStruct *element)
{
    element->p1->p2 = element->p2;
    element->p2->p1 = element->p1;
}

In this code, `element->p2` only needs to be loaded once. However, LLVM loads
`element->p2` again after `element->p1->p2 = element->p2`. Whether or not
`element->p1 == &element` doesn't matter here, since then `element->p2` would
be assigned `element->p2`, so the value would still be known here.

Code from GCC: 

f(testStruct*):
  mov rdx, QWORD PTR [rdi]
  mov rax, QWORD PTR [rdi+8]
  mov QWORD PTR [rdx+8], rax
  mov QWORD PTR [rax], rdx
  ret

Code from LLVM:

f(testStruct*): # @f(testStruct*)
  mov rax, qword ptr [rdi]
  mov rcx, qword ptr [rdi + 8]
  mov qword ptr [rax + 8], rcx
  mov rcx, qword ptr [rdi + 8]
  mov qword ptr [rcx], rax
  ret

-- 
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/20200429/4d097d70/attachment.html>


More information about the llvm-bugs mailing list