From 5b17643ce0eec955661fc950c6d5661826328b2a Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Fri, 22 Jul 2022 09:58:05 +0100 Subject: [PATCH] cranelift: Fix `icmp_imm` for small types in interpreter --- .../filetests/runtests/icmp-eq-imm.clif | 77 +++++++++++++++++++ .../filetests/filetests/runtests/icmp-eq.clif | 1 + .../filetests/filetests/runtests/icmp-ne.clif | 1 + .../filetests/runtests/icmp-sge.clif | 1 + .../filetests/runtests/icmp-sgt.clif | 1 + .../filetests/runtests/icmp-sle.clif | 1 + .../filetests/runtests/icmp-slt.clif | 1 + .../filetests/runtests/icmp-uge.clif | 1 + .../filetests/runtests/icmp-ule.clif | 1 + .../filetests/runtests/icmp-ult.clif | 1 + cranelift/interpreter/src/value.rs | 4 +- 11 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 cranelift/filetests/filetests/runtests/icmp-eq-imm.clif diff --git a/cranelift/filetests/filetests/runtests/icmp-eq-imm.clif b/cranelift/filetests/filetests/runtests/icmp-eq-imm.clif new file mode 100644 index 000000000000..35dc4d481d8d --- /dev/null +++ b/cranelift/filetests/filetests/runtests/icmp-eq-imm.clif @@ -0,0 +1,77 @@ +test interpret +test run +target aarch64 +target x86_64 +target s390x + +function %icmp_imm_eq_i8(i8) -> b1 { +block0(v0: i8): + v1 = icmp_imm eq v0, 0x44 + return v1 +} +; run: %icmp_imm_eq_i8(0) == false +; run: %icmp_imm_eq_i8(-1) == false +; run: %icmp_imm_eq_i8(0x44) == true + +function %icmp_neg_eq_i8(i8) -> b1 { +block0(v0: i8): + v1 = icmp_imm eq v0, 0xf4 + return v1 +} +; run: %icmp_neg_eq_i8(0) == false +; run: %icmp_neg_eq_i8(-1) == false +; run: %icmp_neg_eq_i8(0xf4) == true + +function %icmp_imm_eq_i16(i16) -> b1 { +block0(v0: i16): + v1 = icmp_imm eq v0, 0x4444 + return v1 +} +; run: %icmp_imm_eq_i16(0) == false +; run: %icmp_imm_eq_i16(-1) == false +; run: %icmp_imm_eq_i16(0x4444) == true + +function %icmp_neg_eq_i16(i16) -> b1 { +block0(v0: i16): + v1 = icmp_imm eq v0, 0xff44 + return v1 +} +; run: %icmp_neg_eq_i16(0) == false +; run: %icmp_neg_eq_i16(-1) == false +; run: %icmp_neg_eq_i16(0xff44) == true + +function %icmp_imm_eq_i32(i32) -> b1 { +block0(v0: i32): + v1 = icmp_imm eq v0, 0x4444_4444 + return v1 +} +; run: %icmp_imm_eq_i32(0) == false +; run: %icmp_imm_eq_i32(-1) == false +; run: %icmp_imm_eq_i32(0x4444_4444) == true + +function %icmp_neg_eq_i32(i32) -> b1 { +block0(v0: i32): + v1 = icmp_imm eq v0, 0xffff_4444 + return v1 +} +; run: %icmp_neg_eq_i32(0) == false +; run: %icmp_neg_eq_i32(-1) == false +; run: %icmp_neg_eq_i32(0xffff_4444) == true + +function %icmp_imm_eq_i64(i64) -> b1 { +block0(v0: i64): + v1 = icmp_imm eq v0, 0x4444_4444_4444_4444 + return v1 +} +; run: %icmp_imm_eq_i64(0) == false +; run: %icmp_imm_eq_i64(-1) == false +; run: %icmp_imm_eq_i64(0x4444_4444_4444_4444) == true + +function %icmp_neg_eq_i64(i64) -> b1 { +block0(v0: i64): + v1 = icmp_imm eq v0, 0xffff_ffff_4444_4444 + return v1 +} +; run: %icmp_neg_eq_i64(0) == false +; run: %icmp_neg_eq_i64(-1) == false +; run: %icmp_neg_eq_i64(0xffff_ffff_4444_4444) == true diff --git a/cranelift/filetests/filetests/runtests/icmp-eq.clif b/cranelift/filetests/filetests/runtests/icmp-eq.clif index ccd9c2ffe837..4ad04e4c803e 100644 --- a/cranelift/filetests/filetests/runtests/icmp-eq.clif +++ b/cranelift/filetests/filetests/runtests/icmp-eq.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_eq_i8(i8, i8) -> b1 { block0(v0: i8, v1: i8): diff --git a/cranelift/filetests/filetests/runtests/icmp-ne.clif b/cranelift/filetests/filetests/runtests/icmp-ne.clif index 6e841b876b08..f84ce72a8c89 100644 --- a/cranelift/filetests/filetests/runtests/icmp-ne.clif +++ b/cranelift/filetests/filetests/runtests/icmp-ne.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_ne_i8(i8, i8) -> b1 { block0(v0: i8, v1: i8): diff --git a/cranelift/filetests/filetests/runtests/icmp-sge.clif b/cranelift/filetests/filetests/runtests/icmp-sge.clif index 98981981e75b..246a7dd1d0cc 100644 --- a/cranelift/filetests/filetests/runtests/icmp-sge.clif +++ b/cranelift/filetests/filetests/runtests/icmp-sge.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_sge_i8(i8, i8) -> b1 { diff --git a/cranelift/filetests/filetests/runtests/icmp-sgt.clif b/cranelift/filetests/filetests/runtests/icmp-sgt.clif index c5f036b39f7b..e5002bc5e6b6 100644 --- a/cranelift/filetests/filetests/runtests/icmp-sgt.clif +++ b/cranelift/filetests/filetests/runtests/icmp-sgt.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_sgt_i8(i8, i8) -> b1 { diff --git a/cranelift/filetests/filetests/runtests/icmp-sle.clif b/cranelift/filetests/filetests/runtests/icmp-sle.clif index 586c3a0c1b00..7f2a9df3ceff 100644 --- a/cranelift/filetests/filetests/runtests/icmp-sle.clif +++ b/cranelift/filetests/filetests/runtests/icmp-sle.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_sle_i8(i8, i8) -> b1 { diff --git a/cranelift/filetests/filetests/runtests/icmp-slt.clif b/cranelift/filetests/filetests/runtests/icmp-slt.clif index 89b37904b091..949dfa1eb9c8 100644 --- a/cranelift/filetests/filetests/runtests/icmp-slt.clif +++ b/cranelift/filetests/filetests/runtests/icmp-slt.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_slt_i8(i8, i8) -> b1 { block0(v0: i8, v1: i8): diff --git a/cranelift/filetests/filetests/runtests/icmp-uge.clif b/cranelift/filetests/filetests/runtests/icmp-uge.clif index 8e6bda917fb2..51dc34ae9ab1 100644 --- a/cranelift/filetests/filetests/runtests/icmp-uge.clif +++ b/cranelift/filetests/filetests/runtests/icmp-uge.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_uge_i8(i8, i8) -> b1 { block0(v0: i8, v1: i8): diff --git a/cranelift/filetests/filetests/runtests/icmp-ule.clif b/cranelift/filetests/filetests/runtests/icmp-ule.clif index 38ce80a30911..11b94a9bb0ed 100644 --- a/cranelift/filetests/filetests/runtests/icmp-ule.clif +++ b/cranelift/filetests/filetests/runtests/icmp-ule.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_ule_i8(i8, i8) -> b1 { block0(v0: i8, v1: i8): diff --git a/cranelift/filetests/filetests/runtests/icmp-ult.clif b/cranelift/filetests/filetests/runtests/icmp-ult.clif index c0821afb872f..e201814f4e7b 100644 --- a/cranelift/filetests/filetests/runtests/icmp-ult.clif +++ b/cranelift/filetests/filetests/runtests/icmp-ult.clif @@ -2,6 +2,7 @@ test interpret test run target aarch64 target x86_64 +target s390x function %icmp_ult_i8(i8, i8) -> b1 { block0(v0: i8, v1: i8): diff --git a/cranelift/interpreter/src/value.rs b/cranelift/interpreter/src/value.rs index e90da9e2235c..ad7280bbee90 100644 --- a/cranelift/interpreter/src/value.rs +++ b/cranelift/interpreter/src/value.rs @@ -294,9 +294,7 @@ impl Value for DataValue { Ok(match kind { ValueConversionKind::Exact(ty) => match (self, ty) { // TODO a lot to do here: from bmask to ireduce to raw_bitcast... - (DataValue::I64(n), types::I32) => DataValue::I32(i32::try_from(n)?), - (DataValue::I64(n), types::I64) => DataValue::I64(n), - (DataValue::I64(n), types::I128) => DataValue::I128(n as i128), + (DataValue::I64(n), ty) if ty.is_int() => DataValue::from_integer(n as i128, ty)?, (DataValue::F32(n), types::I32) => DataValue::I32(n.bits() as i32), (DataValue::F64(n), types::I64) => DataValue::I64(n.bits() as i64), (DataValue::B(b), t) if t.is_bool() => DataValue::B(b),