<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 - Is it intended behaviour for LLVM to emit `vpbroadcastd` for a constant on every iteration."
   href="https://bugs.llvm.org/show_bug.cgi?id=46756">46756</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Is it intended behaviour for LLVM to emit `vpbroadcastd` for a constant on every iteration.
          </td>
        </tr>

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

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>denis.yaroshevskij@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is the main loop:

```
.LBB0_8:                                #   Parent Loop BB0_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
        vmovdqa ymm7, ymmword ptr [rdi]
        vpcmpgtd        ymm8, ymm2, ymm7
        vpminsd ymm2, ymm2, ymm7
        vpblendvb       ymm1, ymm1, ymm6, ymm8
        vpbroadcastd    ymm7, dword ptr [rip + .LCPI0_2] # ymm7 =
[8,8,8,8,8,8,8,8]
        vpaddd  ymm6, ymm6, ymm7
        add     rdi, 32
        cmp     rcx, rdi
        jne     .LBB0_8
```

This `vpbroadcastd` that just assigns 8 on every step seems like a bug.
In a similar situation llvm keeps it in the register, see
<a href="https://gcc.godbolt.org/z/94M91c">https://gcc.godbolt.org/z/94M91c</a> for both unrolled and not unrolled cases.

Profiling is inconclusive in terms of if this `broadcast` is a problem:

 0.11  │       data16       data16 data16 data16 nop WORD PTR
cs:[rax+rax*1+0x0]
 0.88  │       vmovdqa      ymm8,YMMWORD PTR [rdi]
 0.27  │       vpcmpgtd     ymm9,ymm5,ymm8
 27.13 │       vpminsd      ymm5,ymm5,ymm8
 30.93 │       vpblendvb    ymm4,ymm4,ymm7,ymm9
       │       vpbroadcastd ymm8,DWORD PTR [rip+0x9974b]

My code you won't be able to compile, but here is a complete disassembly:
<a href="https://github.com/DenisYaroshevskiy/unsq_eve/blob/8dc8e992d9ced36c0a37b8ea6a6ae3eb6e97d6e2/disassemble/disassemble.s#L118">https://github.com/DenisYaroshevskiy/unsq_eve/blob/8dc8e992d9ced36c0a37b8ea6a6ae3eb6e97d6e2/disassemble/disassemble.s#L118</a>

Is this expected? If it's not - can you recommend a workaround?</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>