<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 - Wrong code generated for code sequence shl/ashr/trunc/ashr"
   href="https://bugs.llvm.org/show_bug.cgi?id=49162">49162</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong code generated for code sequence shl/ashr/trunc/ashr
          </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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>carrot@google.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 bug entry is requested by @RKSimon, trunc llvm generates wrong code for
the following test case

define i32* @PRXXXXXX(i32* %base, i160* %ptr160) {
  %load160 = load i160, i160* %ptr160, align 4
  %shl = shl i160 %load160, 80
  %ashr160 = ashr i160 %shl, 112
  %trunc = trunc i160 %ashr160 to i64
  %ashr64 = ashr i64 %trunc, 32
  %gep = getelementptr inbounds i32, i32* %base, i64 %ashr64
  ret i32* %gep
}

PRXXXXXX: # @PRXXXXXX
  lea rax, [rdi - 4]
  ret

Correct result should be

PRXXXXXX: # @PRXXXXXX
  mov eax, dword ptr [rsi + 8]
  shl eax, 16
  cdqe
  sar rax, 16
  lea rax, [rdi + 4*rax]
  ret

It is also demonstrated by <a href="https://godbolt.org/z/snajbG">https://godbolt.org/z/snajbG</a>.

It is caused by patch
<a href="https://reviews.llvm.org/rG69bc0990a9181e6eb86228276d2f59435a7fae67">https://reviews.llvm.org/rG69bc0990a9181e6eb86228276d2f59435a7fae67</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>