Stream: git-wasmtime

Topic: wasmtime / issue #4406 Cranelift: `x86_64` wrong codegen ...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 07 2022 at 17:49):

afonso360 opened issue #4406:

:wave: Hey,

As a followup to #4403, it looks like we are wrongly lowering icmp of and icmp nof on the x86_64 backend for i128 values.

.clif Test Case

test run
set enable_llvm_abi_extensions=true
target x86_64

function %icmp_of_i128(i128, i128) -> b1 {
block0(v0: i128, v1: i128):
  v2 = icmp.i128 of v0, v1
  return v2
}
; run: %icmp_of_i128(0, 0) == false
; run: %icmp_of_i128(0, 1) == false
; run: %icmp_of_i128(0, -1) == false
; run: %icmp_of_i128(-1, -1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == false
; run: %icmp_of_i128(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 1) == true
; run: %icmp_of_i128(1, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == false
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == false

There is a more comprehensive testsuite for this in tree at cranelift/filetests/filetests/runtests/i128-icmp-overflow.clif.

Steps to Reproduce

clif-util test ./the-above.clif

Expected Results

The tests to pass.

Actual Results

     Running `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif`
skipped .\filetests\filetests\runtests\i128-icmp-overflow.clif: host can't run Aarch64(Aarch64) programs
FAIL .\filetests\filetests\runtests\i128-icmp-overflow.clif: run

Caused by:
    Failed test: run: %icmp_of_i128(-170141183460469231731687303715884105728, 1) == true, actual: false
1 tests
Error: 1 failure
error: process didn't exit successfully: `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif` (exit code: 1)

Versions and Environment

Cranelift version or commit: main
Operating system: Windows
Architecture: x86_64

Extra Info

We also do some weird codegen compared to llvm:

Here's what we generate:

push    rbp
mov     rbp, rsp
mov     r10, r8
cmp     rdx, r9
seto    al
sete    r8b
mov     rdx, r10
cmp     rcx, rdx
seto    r9b
and     r8, r9
or      rax, r8
and     rax, 1
mov     rsp, rbp
pop     rbp
ret

VS llvm's implementation:

cmp     rdi, rdx
sbb     rsi, rcx
seto    al
ret

view this post on Zulip Wasmtime GitHub notifications bot (Jul 07 2022 at 17:49):

afonso360 labeled issue #4406:

:wave: Hey,

As a followup to #4403, it looks like we are wrongly lowering icmp of and icmp nof on the x86_64 backend for i128 values.

.clif Test Case

test run
set enable_llvm_abi_extensions=true
target x86_64

function %icmp_of_i128(i128, i128) -> b1 {
block0(v0: i128, v1: i128):
  v2 = icmp.i128 of v0, v1
  return v2
}
; run: %icmp_of_i128(0, 0) == false
; run: %icmp_of_i128(0, 1) == false
; run: %icmp_of_i128(0, -1) == false
; run: %icmp_of_i128(-1, -1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == false
; run: %icmp_of_i128(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 1) == true
; run: %icmp_of_i128(1, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == false
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == false

There is a more comprehensive testsuite for this in tree at cranelift/filetests/filetests/runtests/i128-icmp-overflow.clif.

Steps to Reproduce

clif-util test ./the-above.clif

Expected Results

The tests to pass.

Actual Results

     Running `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif`
skipped .\filetests\filetests\runtests\i128-icmp-overflow.clif: host can't run Aarch64(Aarch64) programs
FAIL .\filetests\filetests\runtests\i128-icmp-overflow.clif: run

Caused by:
    Failed test: run: %icmp_of_i128(-170141183460469231731687303715884105728, 1) == true, actual: false
1 tests
Error: 1 failure
error: process didn't exit successfully: `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif` (exit code: 1)

Versions and Environment

Cranelift version or commit: main
Operating system: Windows
Architecture: x86_64

Extra Info

We also do some weird codegen compared to llvm:

Here's what we generate:

push    rbp
mov     rbp, rsp
mov     r10, r8
cmp     rdx, r9
seto    al
sete    r8b
mov     rdx, r10
cmp     rcx, rdx
seto    r9b
and     r8, r9
or      rax, r8
and     rax, 1
mov     rsp, rbp
pop     rbp
ret

VS llvm's implementation:

cmp     rdi, rdx
sbb     rsi, rcx
seto    al
ret

view this post on Zulip Wasmtime GitHub notifications bot (Jul 07 2022 at 17:49):

afonso360 labeled issue #4406:

:wave: Hey,

As a followup to #4403, it looks like we are wrongly lowering icmp of and icmp nof on the x86_64 backend for i128 values.

.clif Test Case

test run
set enable_llvm_abi_extensions=true
target x86_64

function %icmp_of_i128(i128, i128) -> b1 {
block0(v0: i128, v1: i128):
  v2 = icmp.i128 of v0, v1
  return v2
}
; run: %icmp_of_i128(0, 0) == false
; run: %icmp_of_i128(0, 1) == false
; run: %icmp_of_i128(0, -1) == false
; run: %icmp_of_i128(-1, -1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == false
; run: %icmp_of_i128(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 1) == true
; run: %icmp_of_i128(1, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == false
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == false

There is a more comprehensive testsuite for this in tree at cranelift/filetests/filetests/runtests/i128-icmp-overflow.clif.

Steps to Reproduce

clif-util test ./the-above.clif

Expected Results

The tests to pass.

Actual Results

     Running `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif`
skipped .\filetests\filetests\runtests\i128-icmp-overflow.clif: host can't run Aarch64(Aarch64) programs
FAIL .\filetests\filetests\runtests\i128-icmp-overflow.clif: run

Caused by:
    Failed test: run: %icmp_of_i128(-170141183460469231731687303715884105728, 1) == true, actual: false
1 tests
Error: 1 failure
error: process didn't exit successfully: `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif` (exit code: 1)

Versions and Environment

Cranelift version or commit: main
Operating system: Windows
Architecture: x86_64

Extra Info

We also do some weird codegen compared to llvm:

Here's what we generate:

push    rbp
mov     rbp, rsp
mov     r10, r8
cmp     rdx, r9
seto    al
sete    r8b
mov     rdx, r10
cmp     rcx, rdx
seto    r9b
and     r8, r9
or      rax, r8
and     rax, 1
mov     rsp, rbp
pop     rbp
ret

VS llvm's implementation:

cmp     rdi, rdx
sbb     rsi, rcx
seto    al
ret

view this post on Zulip Wasmtime GitHub notifications bot (Jul 07 2022 at 17:53):

cfallin commented on issue #4406:

cc @abrown @jlb6740

view this post on Zulip Wasmtime GitHub notifications bot (Sep 07 2022 at 15:38):

jameysharp closed issue #4406:

:wave: Hey,

As a followup to #4403, it looks like we are wrongly lowering icmp of and icmp nof on the x86_64 backend for i128 values.

.clif Test Case

test run
set enable_llvm_abi_extensions=true
target x86_64

function %icmp_of_i128(i128, i128) -> b1 {
block0(v0: i128, v1: i128):
  v2 = icmp.i128 of v0, v1
  return v2
}
; run: %icmp_of_i128(0, 0) == false
; run: %icmp_of_i128(0, 1) == false
; run: %icmp_of_i128(0, -1) == false
; run: %icmp_of_i128(-1, -1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == false
; run: %icmp_of_i128(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == false
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 1) == true
; run: %icmp_of_i128(1, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == true
; run: %icmp_of_i128(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == false
; run: %icmp_of_i128(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == false

There is a more comprehensive testsuite for this in tree at cranelift/filetests/filetests/runtests/i128-icmp-overflow.clif.

Steps to Reproduce

clif-util test ./the-above.clif

Expected Results

The tests to pass.

Actual Results

     Running `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif`
skipped .\filetests\filetests\runtests\i128-icmp-overflow.clif: host can't run Aarch64(Aarch64) programs
FAIL .\filetests\filetests\runtests\i128-icmp-overflow.clif: run

Caused by:
    Failed test: run: %icmp_of_i128(-170141183460469231731687303715884105728, 1) == true, actual: false
1 tests
Error: 1 failure
error: process didn't exit successfully: `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\filetests\filetests\runtests\i128-icmp-overflow.clif` (exit code: 1)

Versions and Environment

Cranelift version or commit: main
Operating system: Windows
Architecture: x86_64

Extra Info

We also do some weird codegen compared to llvm:

Here's what we generate:

push    rbp
mov     rbp, rsp
mov     r10, r8
cmp     rdx, r9
seto    al
sete    r8b
mov     rdx, r10
cmp     rcx, rdx
seto    r9b
and     r8, r9
or      rax, r8
and     rax, 1
mov     rsp, rbp
pop     rbp
ret

VS llvm's implementation:

cmp     rdi, rdx
sbb     rsi, rcx
seto    al
ret

Last updated: Oct 23 2024 at 20:03 UTC