<html>
    <head>
      <base href="https://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 --- - instcombine miscompile after r237539"
   href="https://llvm.org/bugs/show_bug.cgi?id=23583">23583</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>instcombine miscompile after r237539
          </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>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>hans@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>james.molloy@arm.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this reduced test case from a 64-bit Chromium build on Linux:

int f() __attribute__((noinline));
int f() { volatile int x = -1; return x; }

void ParseUniformName(unsigned long *outSubscript) {
    int index = f();
    if (index >= 0) {
        *outSubscript = index;
    } else {
        *outSubscript = 0xffffffffu;
    }
}

#include <stdio.h>
int main() {
  unsigned long index = 0xdeadbeef;
  ParseUniformName(&index);
  printf("index = 0x%zx\n", index);

  return 0;
}

The expected output is 0xffffffff, but compiling with ToT Clang at -O3 yields
0xffffffffffffffff instead.

This seems to have regressed at r237539.


Asm before:

_Z16ParseUniformNamePm:                 # @_Z16ParseUniformNamePm
  .cfi_startproc
# BB#0:                                 # %entry
  pushq %rbx
.Ltmp0:
  .cfi_def_cfa_offset 16
.Ltmp1:
  .cfi_offset %rbx, -16
  movq  %rdi, %rbx
  callq _Z1fv
  testl %eax, %eax
  cltq
  movl  $4294967295, %ecx       # imm = 0xFFFFFFFF
  cmovnsq %rax, %rcx
  movq  %rcx, (%rbx)
  popq  %rbx
  retq

Asm after:

_Z16ParseUniformNamePm:                 # @_Z16ParseUniformNamePm
  .cfi_startproc
# BB#0:                                 # %entry
  pushq %rbx
.Ltmp0:
  .cfi_def_cfa_offset 16
.Ltmp1:
  .cfi_offset %rbx, -16
  movq  %rdi, %rbx
  callq _Z1fv
  cmpl  $-2, %eax
  movl  $-1, %ecx
  cmovgl  %eax, %ecx
  movslq  %ecx, %rax
  movq  %rax, (%rbx)
  popq  %rbx
  retq</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>