Advance the insertion cursor after replacinf an instruction.
When expanding iadd_cout, the original instruction is replaced with an iadd, and an icmp is inserted after the iadd. Make sure we advance the insertion position after replacing iadd_cout so the icmp gets inserted *after* iadd.
This commit is contained in:
18
cranelift/filetests/isa/riscv/expand-i32.cton
Normal file
18
cranelift/filetests/isa/riscv/expand-i32.cton
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
; Test the legalization of i32 instructions that don't have RISC-V versions.
|
||||||
|
test legalizer
|
||||||
|
|
||||||
|
set is_64bit=0
|
||||||
|
isa riscv supports_m=1
|
||||||
|
|
||||||
|
set is_64bit=1
|
||||||
|
isa riscv supports_m=1
|
||||||
|
|
||||||
|
; regex: V=vx?\d+
|
||||||
|
|
||||||
|
function carry_out(i32, i32) -> i32, b1 {
|
||||||
|
ebb0(v1: i32, v2: i32):
|
||||||
|
v3, v4 = iadd_cout v1, v2
|
||||||
|
return v3, v4
|
||||||
|
}
|
||||||
|
; check: $v3 = iadd $v1, $v2
|
||||||
|
; check: $(cout=$V) = icmp ult, $v3, $v1
|
||||||
@@ -105,6 +105,7 @@ def wrap_tup(seq):
|
|||||||
def emit_dst_inst(node, fmt):
|
def emit_dst_inst(node, fmt):
|
||||||
# type: (Def, Formatter) -> None
|
# type: (Def, Formatter) -> None
|
||||||
exact_replace = False
|
exact_replace = False
|
||||||
|
replaced_inst = None # type: str
|
||||||
if len(node.defs) == 0:
|
if len(node.defs) == 0:
|
||||||
# This node doesn't define any values, so just insert the new
|
# This node doesn't define any values, so just insert the new
|
||||||
# instruction.
|
# instruction.
|
||||||
@@ -116,6 +117,7 @@ def emit_dst_inst(node, fmt):
|
|||||||
# pattern.
|
# pattern.
|
||||||
# Replace the whole instruction.
|
# Replace the whole instruction.
|
||||||
builder = 'let {} = dfg.replace(inst)'.format(wrap_tup(node.defs))
|
builder = 'let {} = dfg.replace(inst)'.format(wrap_tup(node.defs))
|
||||||
|
replaced_inst = 'inst'
|
||||||
# Secondary values weren't replaced if this is an exact replacement
|
# Secondary values weren't replaced if this is an exact replacement
|
||||||
# for all the src results.
|
# for all the src results.
|
||||||
exact_replace = (node.defs == src_def0.defs)
|
exact_replace = (node.defs == src_def0.defs)
|
||||||
@@ -126,6 +128,14 @@ def emit_dst_inst(node, fmt):
|
|||||||
|
|
||||||
fmt.line('{}.{};'.format(builder, node.expr.rust_builder()))
|
fmt.line('{}.{};'.format(builder, node.expr.rust_builder()))
|
||||||
|
|
||||||
|
# If we just replaced an instruction, we need to bump the cursor so
|
||||||
|
# following instructions are inserted *after* the replaced insruction.
|
||||||
|
if replaced_inst:
|
||||||
|
with fmt.indented(
|
||||||
|
'if pos.current_inst() == Some({}) {{'
|
||||||
|
.format(replaced_inst), '}'):
|
||||||
|
fmt.line('pos.next_inst();')
|
||||||
|
|
||||||
if exact_replace:
|
if exact_replace:
|
||||||
fmt.comment('exactreplacement')
|
fmt.comment('exactreplacement')
|
||||||
|
|
||||||
@@ -151,12 +161,7 @@ def gen_xform(xform, fmt):
|
|||||||
|
|
||||||
def gen_xform_group(xgrp, fmt):
|
def gen_xform_group(xgrp, fmt):
|
||||||
# type: (XFormGroup, Formatter) -> None
|
# type: (XFormGroup, Formatter) -> None
|
||||||
fmt.doc_comment("""
|
fmt.doc_comment("Legalize the instruction pointed to by `pos`.")
|
||||||
Legalize the instruction pointed to by `pos`.
|
|
||||||
|
|
||||||
Return the first instruction in the expansion, and leave `pos` pointing
|
|
||||||
at the last instruction in the expansion.
|
|
||||||
""")
|
|
||||||
fmt.line('#[allow(unused_variables,unused_assignments)]')
|
fmt.line('#[allow(unused_variables,unused_assignments)]')
|
||||||
with fmt.indented(
|
with fmt.indented(
|
||||||
'fn ' + xgrp.name +
|
'fn ' + xgrp.name +
|
||||||
|
|||||||
Reference in New Issue
Block a user