Fix logic bug in requires_typevar_operand.

The Python code computing this property had a bug. The property has only
been used for optimizing the ctrl_typevar() method so far.
This commit is contained in:
Jakob Stoklund Olesen
2017-03-14 13:31:01 -07:00
parent 7db4b1b73a
commit d604855b27
2 changed files with 14 additions and 1 deletions

View File

@@ -445,7 +445,7 @@ def gen_type_constraints(fmt, instrs):
use_typevar_operand = i.is_polymorphic and i.use_typevar_operand
# Can the controlling type variable be inferred from the result?
use_result = (fixed_results > 0 and
i.outs[i.value_results[0]].typevar != ctrl_typevar)
i.outs[i.value_results[0]].typevar == ctrl_typevar)
# Are we required to use the designated operand instead of the
# result?
requires_typevar_operand = use_typevar_operand and not use_result

View File

@@ -627,9 +627,16 @@ mod tests {
fn constraints() {
let a = Opcode::Iadd.constraints();
assert!(a.use_typevar_operand());
assert!(!a.requires_typevar_operand());
assert_eq!(a.fixed_results(), 1);
assert_eq!(a.fixed_value_arguments(), 2);
let b = Opcode::Bitcast.constraints();
assert!(!b.use_typevar_operand());
assert!(!b.requires_typevar_operand());
assert_eq!(b.fixed_results(), 1);
assert_eq!(b.fixed_value_arguments(), 1);
let c = Opcode::Call.constraints();
assert_eq!(c.fixed_results(), 0);
assert_eq!(c.fixed_value_arguments(), 0);
@@ -637,6 +644,12 @@ mod tests {
let i = Opcode::CallIndirect.constraints();
assert_eq!(i.fixed_results(), 0);
assert_eq!(i.fixed_value_arguments(), 1);
let cmp = Opcode::Icmp.constraints();
assert!(cmp.use_typevar_operand());
assert!(cmp.requires_typevar_operand());
assert_eq!(cmp.fixed_results(), 1);
assert_eq!(cmp.fixed_value_arguments(), 2);
}
#[test]