<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Failure to remove useless reload"
   href="https://bugs.llvm.org/show_bug.cgi?id=45737">45737</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Failure to remove useless reload
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>gabravier@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>