<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 - Missed rotate right optimization"
   href="https://bugs.llvm.org/show_bug.cgi?id=37460">37460</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed rotate right optimization
          </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>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,

LLVM doesn't optimize rotate right operation to ror x86 instruction for the
following case:

typedef struct { uint64_t state;  uint64_t inc; } pcg32_random_t;

uint32_t pcg32_random_r(pcg32_random_t* rng) {
    uint64_t oldstate = rng->state;
    rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1);
    uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
    uint32_t rot = oldstate >> 59u;
    return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
}

Clang generates:
pcg32_random_r: # @pcg32_random_r
  mov rcx, qword ptr [rdi]
  mov rax, qword ptr [rdi + 8]
  movabs rdx, 6364136223846793005
  imul rdx, rcx
  or rax, 1
  add rax, rdx
  mov qword ptr [rdi], rax
  mov rax, rcx
  shr rax, 18
  xor rax, rcx
  shr rax, 27
  shr rcx, 59
  mov edx, eax
  shr edx, cl
  neg ecx
  shl eax, cl
  or eax, edx
  ret


Better code, generated from GCC:
pcg32_random_r:
  mov rcx, QWORD PTR [rdi]
  mov rdx, QWORD PTR [rdi+8]
  movabs rax, 6364136223846793005
  imul rax, rcx
  or rdx, 1
  add rax, rdx
  mov QWORD PTR [rdi], rax
  mov rax, rcx
  shr rax, 18
  xor rax, rcx
  shr rcx, 59
  shr rax, 27
  ror eax, cl
  ret



Source:
<a href="https://www.reddit.com/r/rust/comments/8jeybi/rust_does_not_rotate_or_rather_llvm/">https://www.reddit.com/r/rust/comments/8jeybi/rust_does_not_rotate_or_rather_llvm/</a></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>