Create value aliases when necessary.
If a secondary value in the source pattern becomes a primary value in the destination pattern, it is not possible to overwrite the definition of the source value. Instead, change the original source value to an alias to the new promary value.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user