<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 - [WebAssembly] FastISel miscompiles comparison used in different block"
   href="https://bugs.llvm.org/show_bug.cgi?id=51651">51651</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[WebAssembly] FastISel miscompiles comparison used in different block
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Backend: WebAssembly
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nikita.ppv@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>target triple = "wasm32-unknown-unknown"

define i32 @test(i8* %p, i8* %p2) {
  %v = load i8, i8* %p
  %v.ext = zext i8 %v to i32
  %cond = icmp eq i32 %v.ext, 0
  ; Cause FastISel abort.
  %shl = shl i8 %v, 0
  store i8 %shl, i8* %p2
  br label %bb2

bb2:
  br i1 %cond, label %bb3, label %bb4

bb4:
  ret i32 0

bb3:
  ret i32 1
}

; RUN: llc -O0

# %bb.0:
        local.get       0
        i32.load8_u     0
        local.set       2
        local.get       2
        i32.eqz
        drop
        local.get       1
        local.get       2
        i32.store8      0
# %bb.1:                                # %bb2
        block           
        local.get       3
        i32.eqz
        br_if           0                               # 0: down to label0
# %bb.2:                                # %bb4
        i32.const       0
        local.set       4
        local.get       4
        return
.LBB0_3:                                # %bb3
        end_block                               # label0:
        i32.const       1
        local.set       5
        local.get       5
        return
        end_function

Note the local.get 3 reading an uninitialized register.

This is because
<a href="https://github.com/llvm/llvm-project/blob/2f69c82cec1ae05b4fdcef4ac48f48e9e2bad32b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp#L422-L427">https://github.com/llvm/llvm-project/blob/2f69c82cec1ae05b4fdcef4ac48f48e9e2bad32b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp#L422-L427</a>
does not check that the icmp operand is in the same block. FastISel doesn't
allow this kind of cross-block optimization.</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>