riscv64: Fix masking on iabs (#5505)

* cranelift: Add `iabs.i128` runtest

* riscv64: Fix incorrect extension in iabs

When lowering iabs, we were accidentally comparing the unextended value
this caused the instruction to misbehave with certain top bits.

This commit also adds a zbb lowering that does not use jumps.
This commit is contained in:
Afonso Bordado
2023-01-04 01:37:25 +00:00
committed by GitHub
parent 276bc6ad2e
commit 52ba72f341
8 changed files with 172 additions and 15 deletions

View File

@@ -0,0 +1,13 @@
test interpret
test run
target s390x
function %iabs_i128(i128) -> i128 {
block0(v0: i128):
v1 = iabs v0
return v1
}
; run: %iabs_i128(0) == 0
; run: %iabs_i128(-1) == 1
; run: %iabs_i128(1) == 1
; run: %iabs_i128(0x80000000_00000000_00000000_00000000) == 0x80000000_00000000_00000000_00000000

View File

@@ -2,7 +2,8 @@ test interpret
test run
target aarch64
target s390x
target riscv64
target riscv64 has_zbb=false
target riscv64 has_zbb=true
; x86_64 only supports vector iabs
function %iabs_i8(i8) -> i8 {
@@ -44,3 +45,14 @@ block0(v0: i64):
; run: %iabs_i64(9223372036854775807) == 9223372036854775807
; run: %iabs_i64(-9223372036854775807) == 9223372036854775807
; run: %iabs_i64(-9223372036854775808) == -9223372036854775808
; See issue #5501.
; If iabs does not mask the high bits on the input, it can give an incorrect result.
function %iabs_i16_mask(i16, i64) -> i16 system_v {
block0(v0: i16, v1: i64):
v2 = ushr v0, v1
v3 = iabs v2
return v3
}
; run: %iabs_i16_mask(-24064, 16) == 24064