Properly infer result type for single-result instructions.

Polymorphic single-result instructions don't always return the
controlling type variable as their first result. They may use a derived
type variable, as for example icmp does.
This commit is contained in:
Jakob Stoklund Olesen
2016-10-21 11:02:53 -07:00
parent 20aabcd1c7
commit 61f5eeee2f
2 changed files with 44 additions and 1 deletions

View File

@@ -474,7 +474,21 @@ def gen_inst_builder(inst, fmt):
fmt.line(
'let ctrl_typevar = self.data_flow_graph().value_type({});'
.format(inst.ins[inst.format.typevar_operand].name))
args.append('ctrl_typevar')
if inst.format.multiple_results:
# The format constructor will resolve the result types from the
# type var.
args.append('ctrl_typevar')
elif inst.outs[inst.value_results[0]].typ == inst.ctrl_typevar:
# The format constructor expects a simple result type.
# No type transformation needed from the controlling type
# variable.
args.append('ctrl_typevar')
else:
# The format constructor expects a simple result type.
# TODO: This formula could be resolved ahead of time.
args.append(
'Opcode::{}.constraints().result_type(0, ctrl_typevar)'
.format(inst.camel_name))
else:
# This non-polymorphic instruction has a fixed result type.
args.append(