<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 - Intermittent bug in opt with -O3 -newgvn"
   href="https://bugs.llvm.org/show_bug.cgi?id=37676">37676</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Intermittent bug in opt with -O3 -newgvn
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>unassignedclangbugs@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>Created <span class=""><a href="attachment.cgi?id=20388" name="attach_20388" title="Reproducer.">attachment 20388</a> <a href="attachment.cgi?id=20388&action=edit" title="Reproducer.">[details]</a></span>
Reproducer.

Intermittent bug in opt with -O3 -newgvn. 
It gives 2 variants of assembler for different compilations.
opt-bisect-limit points to "Global Value Numbering on function"
Reproducer:
<span class="quote">>$ cat func.c</span >
extern unsigned long long b, e, g;
extern const signed char a;
extern const unsigned c;
extern unsigned d, h;
extern signed char f, i;
extern unsigned *j;
extern unsigned long long *k;
extern signed char *l;
void foo() {
  if (*k <= (8 & -b * ((1 - 8ULL) * c) ?: ~i))
    f = 8 & -(b * ((1 - 8ULL) * c)) ?: i * d;
  e = g ? -(8 & -b * ((1 - 8ULL) * c) ?: i * d) : 0;
  if (!a) {
    *l = ~0 ? 8 & -(b * ((1 - 8ULL) * c)) ?: i * d : 2022409665839104;
    h = 8 & -(b * ((1ULL - 8) * c)) ? b * ((1 - 8ULL) * c) : 0;
  }
  if (8 & -(b * ((1ULL - 8) * c)) ? 0 : ~0)
    *j = b * ((1 - 8ULL) * c);
}
<span class="quote">>$ cat driver.c</span >
#include <stdio.h>
unsigned long long b, e, g;
const signed char a = 8;
const unsigned c = 92620;
unsigned d, h, m;
signed char f, i;
unsigned *j = &m;
unsigned long long *k = &e;
signed char *l;
void foo();
int main() {
  *j = 42;
  foo();
  printf("%u\n", *j);
}

Error:
<span class="quote">>$ clang driver.c func.c
>$ ./a.out</span >
0
<span class="quote">>$ clang -O3 -Xclang -disable-llvm-optzns -emit-llvm -c -o func.bc func.c
>$ opt -O3 -o func.ll func.bc -newgvn
>$ clang -O3 -c -o func.o func.ll
>$ clang -O3 driver.c func.o
>$ ./a.out</span >
42

LLVM version:
clang version 7.0.0 (trunk 333836)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /users/vlivinsk/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>