diff --git a/filetests/isa/riscv/expand-i32.cton b/filetests/isa/riscv/expand-i32.cton index b2473aa608..c0ca7be56f 100644 --- a/filetests/isa/riscv/expand-i32.cton +++ b/filetests/isa/riscv/expand-i32.cton @@ -16,3 +16,6 @@ ebb0(v1: i32, v2: i32): } ; check: $v3 = iadd $v1, $v2 ; check: $(cout=$V) = icmp ult, $v3, $v1 +; It's possible the legalizer will rewrite these value aliases in the future. +; check: $v4 -> $cout +; check: return $v3, $v4 diff --git a/lib/cretonne/meta/gen_legalizer.py b/lib/cretonne/meta/gen_legalizer.py index bc662dca8b..6c154adc56 100644 --- a/lib/cretonne/meta/gen_legalizer.py +++ b/lib/cretonne/meta/gen_legalizer.py @@ -106,6 +106,7 @@ def emit_dst_inst(node, fmt): # type: (Def, Formatter) -> None exact_replace = False replaced_inst = None # type: str + fixup_first_result = False if len(node.defs) == 0: # This node doesn't define any values, so just insert the new # instruction. @@ -125,6 +126,7 @@ def emit_dst_inst(node, fmt): # Insert a new instruction since its primary def doesn't match the # src. builder = 'let {} = dfg.ins(pos)'.format(wrap_tup(node.defs)) + fixup_first_result = node.defs[0].is_output() fmt.line('{}.{};'.format(builder, node.expr.rust_builder())) @@ -139,6 +141,14 @@ def emit_dst_inst(node, fmt): if exact_replace: fmt.comment('exactreplacement') + # Fix up any output vars. + if fixup_first_result: + # The first result of the instruction just inserted is an output var, + # but it was not a primary result in the source pattern. + # We need to change the original value to an alias of the primary one + # we just inserted. + fmt.line('dfg.change_to_alias(src_{0}, {0});'.format(node.defs[0])) + def gen_xform(xform, fmt): # type: (XForm, Formatter) -> None