<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 - wrong code with "opt -gvn -instcombine -jump-threading -structurizecfg -reg2mem -mem2reg -structurizecfg -called-value-propagation""
   href="https://bugs.llvm.org/show_bug.cgi?id=41699">41699</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wrong code with "opt -gvn -instcombine -jump-threading -structurizecfg -reg2mem -mem2reg -structurizecfg -called-value-propagation"
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>8.0
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>cszide@163.com
          </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=21866" name="attach_21866" title=".bc file of the source code">attachment 21866</a> <a href="attachment.cgi?id=21866&action=edit" title=".bc file of the source code">[details]</a></span>
.bc file of the source code

$clang -v
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir:
/home/jack-zhou/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

$clang -O3 -c -emit-llvm  -mllvm -disable-llvm-optzns small.c -o small.bc

$clang small.bc -o small1.out && ./small1.out
checksum = 9ADD2096

$ /home/jack-zhou/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/opt -gvn
-instcombine -jump-threading -structurizecfg -reg2mem -mem2reg -structurizecfg
-called-value-propagation  small.bc -o small-opt.bc

$clang small-opt.bc -o small2.out && ./small2.out
checksum = 56772008

--------------------------------------------------------------
#include <stdio.h>
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef long int int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;

static uint32_t crc32_tab[256];
static uint32_t crc32_context = 0xFFFFFFFFUL;

static void crc32_gentab(void) {
  uint32_t crc;
  const uint32_t poly = 0xEDB88320UL;
  int i, j;

  for (i = 0; i < 256; i++) {
    crc = i;
    for (j = 8; j > 0; j--) {
      if (crc & 1) {
        crc = (crc >> 1) ^ poly;
      } else {
        crc >>= 1;
      }
    }
    crc32_tab[i] = crc;
  }
}

static void crc32_byte(uint8_t b) {
  crc32_context = ((crc32_context >> 8) & 0x00FFFFFF) ^
                  crc32_tab[(crc32_context ^ b) & 0xFF];
}

static void crc32_8bytes(uint64_t val) {
  crc32_byte((val >> 0) & 0xff);
  crc32_byte((val >> 8) & 0xff);
  crc32_byte((val >> 16) & 0xff);
  crc32_byte((val >> 24) & 0xff);
  crc32_byte((val >> 32) & 0xff);
  crc32_byte((val >> 40) & 0xff);
  crc32_byte((val >> 48) & 0xff);
  crc32_byte((val >> 56) & 0xff);
}

static void transparent_crc(uint64_t val) { crc32_8bytes(val); }

#define INT64_MIN (-(9223372036854775807LL) - 1)
#define safe_div_func_int64_t_s_s(_si1, _si2)                                 
\
  ({                                                                          
\
    int64_t si1 = (_si1);                                                     
\
    int64_t si2 = (_si2);                                                     
\
    ((((int64_t)(si2)) == ((int64_t)0)) ||                                    
\
     ((((int64_t)(si1)) == (INT64_MIN)) &&                                    
\
      (((int64_t)(si2)) == ((int64_t)-1))))                                   
\
        ? ((int64_t)(si1))                                                    
\
        : (((int64_t)(si1)) / ((int64_t)(si2)));                              
\
  })

#define safe_div_func_uint8_t_u_u(_ui1, _ui2)                                 
\
  ({                                                                          
\
    uint8_t ui1 = (_ui1);                                                     
\
    uint8_t ui2 = (_ui2);                                                     
\
    (((uint8_t)(ui2)) == ((uint8_t)0))                                        
\
        ? ((uint8_t)(ui1))                                                    
\
        : (((uint8_t)(ui1)) / ((uint8_t)(ui2)));                              
\
  })
//-----------------------------------------------------------------------------
struct {
  int32_t a;
} b = {1};
uint16_t c = 1;
void main() {
  int d = 0;
  crc32_gentab();
  int32_t *e = &b.a;
  uint64_t f = 8;
  printf("%d\n",b.a);
g:
  if (*e)
    for (c = 0; 0;)
      ;
  else {
    int8_t h = 0;
  i:
    for (; 0; f++)
      ;
    if (f)
      goto g;
    if (safe_div_func_uint8_t_u_u(safe_div_func_int64_t_s_s(*e, 0), h))
      goto i;
  }
  transparent_crc(c);
  printf("checksum = %X\n", crc32_context);
}</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>