<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 - Clang miscompiles with -O1. (X86_DAG->DAG_Instruction_Selection_on_function)"
   href="https://bugs.llvm.org/show_bug.cgi?id=37060">37060</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang miscompiles with -O1. (X86_DAG->DAG_Instruction_Selection_on_function)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>Vsevolod.Livinskij@frtk.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang miscompiles testcase starting from optimization level -O1. opt-bisect
points to X86_DAG->DAG_Instruction_Selection_on_function.

Reproducer:
<span class="quote">>$ cat main.c</span >
#include <stdio.h>

const int b = 1545269876;
const int c = -1355305896;
const int * d = &(b);
int e = -1421384539;

extern void tf_0_foo();

int main () {
    tf_0_foo ();

    printf("%d\n", e);
    return 0;
}

<span class="quote">>$ cat func.c</span >
extern const int tf_0_var_6;
extern const int c;
extern int e;
extern const int * d;

void tf_0_foo() {
  short a = ~0 % c;
  e = (unsigned char)(a ^ *d);
}

Error:
<span class="quote">>$ clang  -w -O0 main.c func.c ; ./a.out</span >
139
<span class="quote">>$ clang  -w -O3 main.c func.c ; ./a.out</span >
-117

LLVM version:
clang version 7.0.0 (trunk 329488)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: llvm/bin-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64</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>