<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 - Byte swap idioms for only part of a wider integer value produce suboptimal code"
   href="https://bugs.llvm.org/show_bug.cgi?id=39793">39793</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Byte swap idioms for only part of a wider integer value produce suboptimal code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>fabiang@radgametools.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Reduced from a bug reported on llvm-dev.

-

#include <stdint.h>

uint64_t f(uint64_t x)
{
    return ((x & 0xff000000ul) >> 3 * 8)
         | ((x & 0x00ff0000ul) >>     8)
         | ((x & 0x0000ff00ul) <<     8)
         | ((x & 0x000000fful) << 3 * 8);
}

uint64_t g(uint64_t x)
{
    uint32_t y = (uint32_t)x;
    return ((y & 0xff000000u) >> 3 * 8)
         | ((y & 0x00ff0000u) >>     8)
         | ((y & 0x0000ff00u) <<     8)
         | ((y & 0x000000ffu) << 3 * 8);
}

-

compiled for target x86_64-linux-gnu at -O2 results in this IR:

-

; Function Attrs: norecurse nounwind readnone uwtable
define dso_local i64 @f(i64) local_unnamed_addr #0 {
  %2 = lshr i64 %0, 24
  %3 = and i64 %2, 255
  %4 = lshr i64 %0, 8
  %5 = and i64 %4, 65280
  %6 = or i64 %3, %5
  %7 = shl i64 %0, 8
  %8 = and i64 %7, 16711680
  %9 = or i64 %6, %8
  %10 = shl i64 %0, 24
  %11 = and i64 %10, 4278190080
  %12 = or i64 %9, %11
  ret i64 %12
}

; Function Attrs: nounwind readnone uwtable
define dso_local i64 @g(i64) local_unnamed_addr #1 {
  %2 = trunc i64 %0 to i32
  %3 = tail call i32 @llvm.bswap.i32(i32 %2)
  %4 = zext i32 %3 to i64
  ret i64 %4
}

-

Ideally, the output for f should match g.

This would require matching the byte reverse patterns for a narrower sub-type
as well, and inserting trunc/zext around it (as in the code for g). Not sure
how complicated that ends up being.</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>