<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - extra movz [x86, Intel, partial register update]"
   href="http://llvm.org/bugs/show_bug.cgi?id=22532">22532</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>extra movz [x86, Intel, partial register update]
          </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>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </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>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is related to the discussion in <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - LLVM not using cmpb for unsigned char comparison"
   href="show_bug.cgi?id=22473">bug 22473</a> and may be the same issue as <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - extra zeroing move operation executed"
   href="show_bug.cgi?id=17113">bug
17113</a> but with a simpler test case:

unsigned char f(unsigned char a, unsigned char b) { 
  return a == b; 
}

Or as IR:
define zeroext i8 @g(i8 zeroext %a, i8 zeroext %b) {
  %cmp = icmp eq i8 %a, %b
  %conv = zext i1 %cmp to i8
  ret i8 %conv
}

This becomes:
    cmpl    %esi, %edi
    sete    %al
    movzbl    %al, %eax  <--- is this zext good for perf?
    retq

There seems to be empirical evidence (see <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - LLVM not using cmpb for unsigned char comparison"
   href="show_bug.cgi?id=22473">bug 22473</a>) that zexts help
performance on SandyBridge because they help avoid partial register stalls.
This is despite Intel's docs (section 3.5.2.4 of the Optimization Reference
Manual) that suggest this isn't a big deal on SandyBridge or later.

Now, if this is a perf win for some Intel chips, then we're still not getting
it right all the time:

// C99 version: use bool return instead of unsigned char
#include <stdbool.h>
bool g(unsigned char a, unsigned char b) { 
  return a == b; 
}

Or as IR:
define zeroext i1 @g(i8 zeroext %a, i8 zeroext %b) #0 {
  %cmp = icmp eq i8 %a, %b
  ret i1 %cmp
}

This has no 'movzbl':
    cmpl    %esi, %edi
    sete    %al
    retq


And regardless of the perf question, we generate the 'movzbl' for f() with -Oz;
that can't be right.</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>