<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 - Optimizer does wrong load elimination after a branch"
   href="https://bugs.llvm.org/show_bug.cgi?id=49939">49939</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Optimizer does wrong load elimination after a branch
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>LLVM Codegen
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24746" name="attach_24746" title="Wrong displacement in "mov" instruction highlighted">attachment 24746</a> <a href="attachment.cgi?id=24746&action=edit" title="Wrong displacement in "mov" instruction highlighted">[details]</a></span>
Wrong displacement in "mov" instruction highlighted

I don't know what exactly goes wrong here. Looks like LLVM 11.0.0 optimizer
generates wrong IR, if Clang is asked to compile this program:

clang -v -std=c99 -masm=intel -O3 -finline-hint-functions -S bug.c

// bug.c
#include <stdint.h>

typedef unsigned char byte;
typedef uint32_t      udword;

typedef struct {
    udword x, y, z;
} A;


udword foo(A *s, udword n) {
    return s->x + n;
}

void bar(byte *ptr, A *s) {
    if (s->y == s->z) 
        *(ptr + 1) = foo(s, s->z * 3); // -O3 calculates s->y * 3 instead
    *ptr = foo(s, s->y);
}</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>