Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cranelift: Interpreter returns the wrong result for vall_true.i8x16 #5916

Closed
afonso360 opened this issue Mar 2, 2023 · 3 comments · Fixed by #6708
Closed

Cranelift: Interpreter returns the wrong result for vall_true.i8x16 #5916

afonso360 opened this issue Mar 2, 2023 · 3 comments · Fixed by #6708
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift:E-easy Issues suitable for newcomers to investigate, including Rust newcomers! cranelift Issues related to the Cranelift code generator good first issue Issues that are good for new contributors to tackle!

Comments

@afonso360
Copy link
Contributor

afonso360 commented Mar 2, 2023

👋 Hey,

.clif Test Case

test interpret

function %a(i8x16) -> i8 {
block0(v0: i8x16):
    v20 = vall_true v0
    return v20
}

; run: %a(0xe66021830506f2fffdfebfc8c8c8c8c8) == 1

Steps to Reproduce

  • cd cranelift
  • cargo run -- test ./the-above.clif

Expected Results

The test to pass

Actual Results

     Running `/home/afonso/git/wasmtime/target/debug/clif-util test ./lmao.clif`
 ERROR cranelift_filetests::concurrent > FAIL: interpret
FAIL ./lmao.clif: interpret

Caused by:
    Failed test: run: %a(0xe66021830506f2fffdfebfc8c8c8c8c8) == 1, actual: 0
1 tests
Error: 1 failure

Versions and Environment

Cranelift version or commit: main

Operating system: Linux

Architecture: Interpreter (x86_64 host)

Extra Info

If anyone needs help looking into this, let me know!

@afonso360 afonso360 added bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator good first issue Issues that are good for new contributors to tackle! cranelift:E-easy Issues suitable for newcomers to investigate, including Rust newcomers! labels Mar 2, 2023
afonso360 added a commit to afonso360/wasmtime that referenced this issue Mar 3, 2023
This is broken in the interpreter bytecodealliance#5916
afonso360 added a commit to afonso360/wasmtime that referenced this issue Mar 9, 2023
This is broken in the interpreter bytecodealliance#5916
afonso360 added a commit that referenced this issue Mar 11, 2023
* fuzzgen: Add some SIMD instructions

* fuzzgen: Remove `scalar_to_vector`

Broken in the interpreter #5911

* fuzzgen: Remove SIMD bitcasts

Broken in the interpreter #5915

* fuzzgen: Fix insert lane

* fuzzgen: Remove debug code

* fuzzgen: Remove vall_true

This is broken in the interpreter #5916

* fuzzgen: Disable a few more ops

* fuzzgen: Remove `iadd_pairwise.i64x2`

Turns out it doesen't exist

* fuzzgen: Remove scalar `sqmul_round_sat`

#5923

* fuzzgen: Disable aligned loads to SIMD values

* fuzzgen: Address Review Feedback

Co-Authored-By: Jamey Sharp <jsharp@fastly.com>

* fuzzgen: Rework `cmp` exclusion rules

Co-Authored-By: Jamey Sharp <jsharp@fastly.com>

---------

Co-authored-by: Jamey Sharp <jsharp@fastly.com>
afonso360 added a commit to afonso360/wasmtime that referenced this issue Mar 13, 2023
…alliance#5971)

* fuzzgen: Add some SIMD instructions

* fuzzgen: Remove `scalar_to_vector`

Broken in the interpreter bytecodealliance#5911

* fuzzgen: Remove SIMD bitcasts

Broken in the interpreter bytecodealliance#5915

* fuzzgen: Fix insert lane

* fuzzgen: Remove debug code

* fuzzgen: Remove vall_true

This is broken in the interpreter bytecodealliance#5916

* fuzzgen: Disable a few more ops

* fuzzgen: Remove `iadd_pairwise.i64x2`

Turns out it doesen't exist

* fuzzgen: Remove scalar `sqmul_round_sat`

bytecodealliance#5923

* fuzzgen: Disable aligned loads to SIMD values

* fuzzgen: Address Review Feedback

Co-Authored-By: Jamey Sharp <jsharp@fastly.com>

* fuzzgen: Rework `cmp` exclusion rules

Co-Authored-By: Jamey Sharp <jsharp@fastly.com>

---------

Co-authored-by: Jamey Sharp <jsharp@fastly.com>
@ms140569
Copy link
Contributor

ms140569 commented Jun 1, 2023

I like to take a look into it. Should I claim this somewhere/somehow?

@afonso360
Copy link
Contributor Author

Awesome! I think that comment is probably enough. Let me know if you run into any issues!

@ms140569
Copy link
Contributor

ms140569 commented Jun 7, 2023

I could reproduce this bug on aarch64 (apple) interpreter as well. The compiler for both linux x86_64 and aarch64 works just fine. I've doublechecked with this:

test compile

function %a(i8x16) -> i8 {
block0(v0: i8x16):
    v20 = vall_true v0
    return v20
}

; run: %a(0x00000000000000000000000000000000) == 0
; run: %a(0xffffffffffffffffffffffffffffff00) == 0
; run: %a(0x00ffffffffffffffffffffffffffffff) == 0
; run: %a(0xffffffffffffff00ffffffffffffffff) == 0
; run: %a(0x01010101010101010101010101010101) == 1
; run: %a(0xffffffffffffffffffffffffffffffff) == 1
; run: %a(0xe66021830506f2fffdfebfc8c8c8c8c8) == 1

; Kick this file off:
;  target/debug/clif-util run ~/prj/wasm/bug/vall-true-5916-compiler.clif

; The definition of vall_true:
;  from: cranelift/codegen/meta/src/shared/instructions.rs
;
; "Reduce a vector to a scalar boolean.
; Return a scalar boolean true if all lanes in ``i`` are non-zero, false otherwise."

The problem seems to be the AND operation in the interpreter here:

https://github.com/bytecodealliance/wasmtime/blob/b357b1b1e922a28990ed39cb8fe763add096de5c/cranelift/interpreter/src/step.rs#LL1046C82-L1046C85

I'll try to come up with a (performant) fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift:E-easy Issues suitable for newcomers to investigate, including Rust newcomers! cranelift Issues related to the Cranelift code generator good first issue Issues that are good for new contributors to tackle!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants