<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 - [SchedModel] Missing ReadAdvance for the source (non dest) operand of RMW instructions."
   href="https://bugs.llvm.org/show_bug.cgi?id=51322">51322</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SchedModel] Missing ReadAdvance for the source (non dest) operand of RMW instructions.
          </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>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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>andrea.dibiagio@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is similar to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [SchedModel] Missing ReadAdvance on the implicit use of EFLAGS in RM and MR variants of ADC/SBB"
   href="show_bug.cgi?id=51318">bug 51318</a>. However, it doesn't only affect ADC/SBB but any
RMW arithmetic opcode.

Example:
```
add  %eax, %eax
add  %eax, 4(%rsp)
```

<span class="quote">> llvm-mca -mcpu=btver2 -iterations=1 -timeline</span >

```
Timeline view:
Index     0123456789

[0,0]     DeER .   .   addl     %eax, %eax
[0,1]     D=eeeeeeER   addl     %eax, (%rsp)
```

EAX is written in 1cy. However, the load from RSP can start immediately, and
doesn't need to be delayed for 1cy.

This is the expected timeline:

```
Timeline view:
Index     012345678

[0,0]     DeER .  .   addl      %eax, %eax
[0,1]     DeeeeeeER   addl      %eax, 4(%rsp)
```

The issue is with the definition of WriteALURMW. it is caused by the absence of
a ReadAdvance for the register operand.


According to llvm-mc:

```
        addl    %eax, 4(%rsp)                   # <MCInst #380 ADD32mr
                                        #  <MCOperand Reg:58>
                                        #  <MCOperand Imm:1>
                                        #  <MCOperand Reg:0>
                                        #  <MCOperand Imm:4>
                                        #  <MCOperand Reg:0>
                                        #  <MCOperand Reg:22>>
```

The first 5 MCOperands are for the memory reference 4(%rsp).
The read at index #5 is currently not marked as ReadAfterLd.

Same problem affects ADC/SBB, for which we use an almost identical pattern,
except that WriteADCRMW is used instead of WriteALURMW.

For those instructions, we also need to mark with ReadAfterLd the implcit read
of EFLAGS.</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>