cranelift: Exclude the control type in narrower and wider (#6018)

* Don't include the control type in `narrower` or `wider` constraints

* Add verifier tests for instructions that use narrower and wider
This commit is contained in:
Trevor Elliott
2023-03-14 11:09:15 -07:00
committed by GitHub
parent f5ad74e546
commit e4d9bb7c5a
2 changed files with 19 additions and 13 deletions

View File

@@ -777,13 +777,13 @@ impl OperandConstraint {
tys.lanes = BitSet::from_range(0, 1); tys.lanes = BitSet::from_range(0, 1);
if ctrl_type.is_int() { if ctrl_type.is_int() {
// The upper bound in from_range is exclusive, so add one here get the closed // The upper bound in from_range is exclusive, and we want to exclude the
// interval of [I8, ctrl_type]. // control type to construct the interval of [I8, ctrl_type).
tys.ints = BitSet::from_range(3, ctrl_type_bits as u8 + 1); tys.ints = BitSet::from_range(3, ctrl_type_bits as u8);
} else if ctrl_type.is_float() { } else if ctrl_type.is_float() {
// The upper bound in from_range is exclusive, so add one here get the closed // The upper bound in from_range is exclusive, and we want to exclude the
// interval of [F32, ctrl_type]. // control type to construct the interval of [F32, ctrl_type).
tys.floats = BitSet::from_range(5, ctrl_type_bits as u8 + 1); tys.floats = BitSet::from_range(5, ctrl_type_bits as u8);
} else { } else {
panic!("The Narrower constraint only operates on floats or ints"); panic!("The Narrower constraint only operates on floats or ints");
} }
@@ -797,13 +797,15 @@ impl OperandConstraint {
tys.lanes = BitSet::from_range(0, 1); tys.lanes = BitSet::from_range(0, 1);
if ctrl_type.is_int() { if ctrl_type.is_int() {
// The upper bound should include all types wider than `ctrl_type`, so we use // The interval should include all types wider than `ctrl_type`, so we use
// `2^8` as the upper bound to define the closed range `[ctrl_type, I128]`. // `2^8` as the upper bound, and add one to the bits of `ctrl_type` to define
tys.ints = BitSet::from_range(ctrl_type_bits as u8, 8); // the interval `(ctrl_type, I128]`.
tys.ints = BitSet::from_range(ctrl_type_bits as u8 + 1, 8);
} else if ctrl_type.is_float() { } else if ctrl_type.is_float() {
// The upper bound should include all float types wider than `ctrl_type`, so we // The interval should include all float types wider than `ctrl_type`, so we
// use `2^7` as the upper bound to define the closed range `[ctrl_type, F64]`. // use `2^7` as the upper bound, and add one to the bits of `ctrl_type` to
tys.floats = BitSet::from_range(ctrl_type_bits as u8, 7); // define the interval `(ctrl_type, F64]`.
tys.floats = BitSet::from_range(ctrl_type_bits as u8 + 1, 7);
} else { } else {
panic!("The Wider constraint only operates on floats or ints"); panic!("The Wider constraint only operates on floats or ints");
} }

View File

@@ -114,13 +114,15 @@ function %bad_extend() {
block0: block0:
v0 = iconst.i32 10 v0 = iconst.i32 10
v1 = uextend.i16 v0 ; error: arg 0 (v0) with type i32 failed to satisfy type set v1 = uextend.i16 v0 ; error: arg 0 (v0) with type i32 failed to satisfy type set
v2 = uextend.i32 v0 ; error: arg 0 (v0) with type i32 failed to satisfy type set
return return
} }
function %bad_reduce() { function %bad_reduce() {
block0: block0:
v0 = iconst.i32 10 v0 = iconst.i32 10
v1 = ireduce.i64 v0 ; error: arg 0 (v0) with type i32 failed to satisfy type set v1 = ireduce.i32 v0 ; error: arg 0 (v0) with type i32 failed to satisfy type set
v2 = ireduce.i64 v0 ; error: arg 0 (v0) with type i32 failed to satisfy type set
return return
} }
@@ -128,6 +130,7 @@ function %bad_fdemote() {
block0: block0:
v0 = f32const 0xf.f v0 = f32const 0xf.f
v1 = fdemote.f64 v0 ; error: arg 0 (v0) with type f32 failed to satisfy type set v1 = fdemote.f64 v0 ; error: arg 0 (v0) with type f32 failed to satisfy type set
v2 = fdemote.f32 v0 ; error: arg 0 (v0) with type f32 failed to satisfy type set
return return
} }
@@ -135,6 +138,7 @@ function %bad_fpromote() {
block0: block0:
v0 = f64const 0xf.f v0 = f64const 0xf.f
v1 = fpromote.f32 v0 ; error: arg 0 (v0) with type f64 failed to satisfy type set v1 = fpromote.f32 v0 ; error: arg 0 (v0) with type f64 failed to satisfy type set
v2 = fpromote.f64 v0 ; error: arg 0 (v0) with type f64 failed to satisfy type set
return return
} }