Skip to content

Commit 88be614

Browse files
committed
Extract x64 brcond selection into dedicated function
The logic there will soon get even more complex.
1 parent debc86f commit 88be614

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

crates/codegen/src/target/x64/lower.rs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -207,29 +207,7 @@ impl MachineLower for X64Machine {
207207
&[],
208208
);
209209
}
210-
NodeKind::BrCond => {
211-
let [cond] = ctx.node_inputs_exact(node);
212-
if ctx.has_one_use(cond) {
213-
match_value! {
214-
if let node cond_node @ &NodeKind::Icmp(kind) = ctx, cond {
215-
let cond_code = select_icmp(ctx, cond_node, kind);
216-
ctx.emit_instr(
217-
X64Instr::Jumpcc(cond_code, targets[0], targets[1]),
218-
&[],
219-
&[],
220-
);
221-
return Ok(());
222-
}
223-
}
224-
}
225-
226-
emit_alu_rr_discarded(ctx, cond, cond, AluBinOp::Test);
227-
ctx.emit_instr(
228-
X64Instr::Jumpcc(CondCode::Ne, targets[0], targets[1]),
229-
&[],
230-
&[],
231-
);
232-
}
210+
NodeKind::BrCond => select_brcond(ctx, node, targets[0], targets[1]),
233211
NodeKind::Return => match ctx.node_inputs(node).next() {
234212
None => ctx.emit_instr(X64Instr::Ret, &[], &[]),
235213
Some(retval) => {
@@ -545,6 +523,35 @@ fn select_addr_base(
545523
AddrBase::Reg
546524
}
547525

526+
fn select_brcond(
527+
ctx: &mut IselContext<'_, '_, X64Machine>,
528+
node: Node,
529+
true_target: Block,
530+
false_target: Block,
531+
) {
532+
let [cond] = ctx.node_inputs_exact(node);
533+
if ctx.has_one_use(cond) {
534+
match_value! {
535+
if let node cond_node @ &NodeKind::Icmp(kind) = ctx, cond {
536+
let cond_code = select_icmp(ctx, cond_node, kind);
537+
ctx.emit_instr(
538+
X64Instr::Jumpcc(cond_code, true_target, false_target),
539+
&[],
540+
&[],
541+
);
542+
return;
543+
}
544+
}
545+
}
546+
547+
emit_alu_rr_discarded(ctx, cond, cond, AluBinOp::Test);
548+
ctx.emit_instr(
549+
X64Instr::Jumpcc(CondCode::Ne, true_target, false_target),
550+
&[],
551+
&[],
552+
);
553+
}
554+
548555
// Raw emission helpers
549556

550557
fn emit_funcaddr(

0 commit comments

Comments
 (0)