<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 - Ashr does not alter sign bit - could look past ashr, backend fails to undo transform"
   href="https://bugs.llvm.org/show_bug.cgi?id=44025">44025</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Ashr does not alter sign bit - could look past ashr, backend fails to undo transform
          </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>lebedev.ri@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I'm not sure how relevant this is, but i noticed this while looking at some
code.
We could have something like:

#include <algorithm>
struct S {
    int a, b;
};
unsigned long zz(S s) {
    return std::abs(static_cast<signed long>(s.a)); // or s.b
}

Currently it ends as 

define dso_local i64 @_Z2zz1S(i64 %0) local_unnamed_addr #0 {
  %2 = shl i64 %0, 32
  %3 = ashr exact i64 %2, 32
  %4 = sub nsw i64 0, %3
  %5 = icmp slt i64 %3, 0
  %6 = select i1 %5, i64 %4, i64 %3
  ret i64 %6
}

        movsxd  rcx, edi
        mov     rax, rcx
        neg     rax
        cmovl   rax, rcx

But we are checking sign bit of %3, which is ashr, and it preserves sign bit.
We could look past it: <a href="https://rise4fun.com/Alive/iANsl">https://rise4fun.com/Alive/iANsl</a>

But that exposes a weakness in backend part - it doesn't know that it could
undo such transform, and not perform the test:

        movsxd  rcx, edi
        shl     rdi, 32
        mov     rax, rcx
        neg     rax
        test    rdi, rdi
        cmovns  rax, rcx

<a href="https://godbolt.org/z/Hr4ceT">https://godbolt.org/z/Hr4ceT</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>