llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.37k stars 12.14k forks source link

Miscompile with multivalue ABI #98323

Open nikic opened 4 months ago

nikic commented 4 months ago

From https://github.com/rust-lang/rust/issues/127318:

; RUN: llc -mtriple=wasm32-unknown-unknown -target-abi=experimental-mv
define i64 @test() {
entry:
  %pair = call { i64, i64 } @foo()
  %v0 = extractvalue { i64, i64 } %pair, 0
  %1 = icmp eq i64 %v0, 0
  %v1 = extractvalue { i64, i64 } %pair, 1
  %_0.sroa.0.0 = select i1 %1, i64 42, i64 %v1
  ret i64 %_0.sroa.0.0
}

declare { i64, i64 } @foo()

Results in:

    i64.const   42
    local.get   0
    call    foo
    local.set   0
    i64.eqz
    i64.select

Note the get-before-set of local 0.

llvmbot commented 4 months ago

@llvm/issue-subscribers-backend-webassembly

Author: Nikita Popov (nikic)

From https://github.com/rust-lang/rust/issues/127318: ```llvm ; RUN: llc -mtriple=wasm32-unknown-unknown -target-abi=experimental-mv define i64 @test() { entry: %pair = call { i64, i64 } @foo() %v0 = extractvalue { i64, i64 } %pair, 0 %1 = icmp eq i64 %v0, 0 %v1 = extractvalue { i64, i64 } %pair, 1 %_0.sroa.0.0 = select i1 %1, i64 42, i64 %v1 ret i64 %_0.sroa.0.0 } declare { i64, i64 } @foo() ``` Results in: ``` i64.const 42 local.get 0 call foo local.set 0 i64.eqz i64.select ``` Note the get-before-set of local 0.
temeddix commented 2 months ago

Is there any update on this issue? This bug is kind of severe, as any feature that use multivalue ABI like u128 leads to maximum call stack error.

This affect many features including:

tlively commented 2 months ago

Can you work around the issue by not using multivalue for now?