<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 --- - Missed optimization opportunity in 3-way unsigned integer comparison case"
   href="http://llvm.org/bugs/show_bug.cgi?id=19758">19758</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimization opportunity in 3-way unsigned integer comparison case
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.3
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>yuri@tsoft.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>From testcases for int and unsigned comparisons it is obvious that llvm uses
two cmpl instructions in unsigned case, and only one in signed case. unsigned
comparision can also be done with only one cmpl instruction, see the procedure
below.

rev.208525



--- testcase: int comparison ---

int mycmp (int i1, int i2) {
  if (i1<i2) 
    return -1;
  else if (i1>i2)
    return 1;
  return 0;
}

        .text
        .file   "cmpi.c"
        .globl  mycmp
        .align  16, 0x90
        .type   mycmp,@function
mycmp:
        pushq   %rbp
        movq    %rsp, %rbp
        movl    $-1, %eax
        cmpl    %esi, %edi
        jl      .LBB0_2
        setg    %al
        movzbl  %al, %eax
.LBB0_2:
        popq    %rbp
        retq
.Ltmp3:
        .size   mycmp, .Ltmp3-mycmp


--- testcase: unsigned comparison ---

int mycmp (unsigned i1, unsigned i2) {
  if (i1<i2) 
    return -1;
  else if (i1>i2) 
    return 1;
  return 0;
}

        .text
        .file   "cmpu.c"
        .globl  mycmp
        .align  16, 0x90
        .type   mycmp,@function
mycmp:
        pushq   %rbp
        movq    %rsp, %rbp
        movl    $-1, %eax
        cmpl    %esi, %edi
        jb      .LBB0_2
        cmpl    %edi, %esi
        sbbl    %eax, %eax
        andl    $1, %eax
.LBB0_2:
        popq    %rbp
        retq
.Ltmp3:
        .size   mycmp, .Ltmp3-mycmp


--- the correct way to do an unsigned comparison ---
        .text
        .file   "cmp.c"
        .globl  mycmp
        .align  16, 0x90
        .type   mycmp,@function
mycmp:
        pushq   %rbp
        movq    %rsp, %rbp
        movl    $-1, %eax
        cmpl    %edi, %esi
        ja      .LBB0_2
        sbbl    %eax, %eax
        andl    $1, %eax
.LBB0_2:
        popq    %rbp
        retq
.Ltmp3:
        .size   mycmp, .Ltmp3-mycmp</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>