Skip to content

Commit

Permalink
cranelift: Fix icmp_imm for small types in interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Jul 22, 2022
1 parent 35b750a commit 5b17643
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 3 deletions.
77 changes: 77 additions & 0 deletions cranelift/filetests/filetests/runtests/icmp-eq-imm.clif
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-eq.clif
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-ne.clif
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-sge.clif
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test interpret
test run
target aarch64
target x86_64
target s390x


function %icmp_sge_i8(i8, i8) -> b1 {
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-sgt.clif
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test interpret
test run
target aarch64
target x86_64
target s390x


function %icmp_sgt_i8(i8, i8) -> b1 {
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-sle.clif
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test interpret
test run
target aarch64
target x86_64
target s390x


function %icmp_sle_i8(i8, i8) -> b1 {
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-slt.clif
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-uge.clif
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-ule.clif
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/icmp-ult.clif
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions cranelift/interpreter/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 5b17643

Please sign in to comment.