[llvm-bugs] [Bug 51651] New: [WebAssembly] FastISel miscompiles comparison used in different block

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 27 12:05:55 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51651

            Bug ID: 51651
           Summary: [WebAssembly] FastISel miscompiles comparison used in
                    different block
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: WebAssembly
          Assignee: unassignedbugs at nondot.org
          Reporter: nikita.ppv at gmail.com
                CC: llvm-bugs at lists.llvm.org

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210827/a54d288b/attachment.html>


More information about the llvm-bugs mailing list