Skip to content

Commit 0ab9d84

Browse files
committed
Add x64 isel support for the float constant 0
This is the only constant that doesn't require constant pool support, so let's get it out of the way.
1 parent 7c964ea commit 0ab9d84

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::mem;
33
use alloc::vec::Vec;
44

55
use ir::{
6-
node::{FcmpKind, FunctionRef, IcmpKind, MemSize, NodeKind, Type},
6+
node::{BitwiseF64, FcmpKind, FunctionRef, IcmpKind, MemSize, NodeKind, Type},
77
valgraph::{DepValue, Node},
88
};
99
use smallvec::{SmallVec, smallvec};
@@ -191,6 +191,7 @@ impl MachineLower for X64Machine {
191191
// `setcc` output register.
192192
emit_setcc_sequence(ctx, output, |ctx| select_icmp(ctx, node, kind));
193193
}
194+
&NodeKind::Fconst64(val) => select_fconst64(ctx, node, val)?,
194195
NodeKind::Fadd => emit_fpu_rr(ctx, node, SseFpuBinOp::Add),
195196
NodeKind::Fsub => emit_fpu_rr(ctx, node, SseFpuBinOp::Sub),
196197
NodeKind::Fmul => emit_fpu_rr(ctx, node, SseFpuBinOp::Mul),
@@ -401,6 +402,22 @@ fn select_icmp(ctx: &mut IselContext<'_, '_, X64Machine>, node: Node, kind: Icmp
401402
cond_code_for_icmp(kind)
402403
}
403404

405+
fn select_fconst64(
406+
ctx: &mut IselContext<'_, '_, X64Machine>,
407+
node: Node,
408+
val: BitwiseF64,
409+
) -> Result<(), MachineIselError> {
410+
let [output] = ctx.node_outputs_exact(node);
411+
let output = ctx.get_value_vreg(output);
412+
413+
if val.bits() == 0 {
414+
ctx.emit_instr(X64Instr::SseMovRZ, &[DefOperand::any_reg(output)], &[]);
415+
return Ok(());
416+
}
417+
418+
Err(MachineIselError)
419+
}
420+
404421
fn select_direct_fcmp(ctx: &mut IselContext<'_, '_, X64Machine>, node: Node, kind: FcmpKind) {
405422
let [output] = ctx.node_outputs_exact(node);
406423
let [op1, op2] = ctx.node_inputs_exact(node);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# run: codegen
2+
3+
func @zero64:f64() {
4+
# check: function `zero64`:
5+
# nextln: 000000: 55 push rbp
6+
# nextln: 000001: 48 89 e5 mov rbp, rsp
7+
# nextln: 000004: 0f 57 c0 xorps xmm0, xmm0
8+
# nextln: 000007: 5d pop rbp
9+
# nextln: 000008: c3 ret
10+
11+
%c:ctrl = entry
12+
%0:f64 = fconst64 0x0
13+
return %c, %0
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# run: isel
2+
3+
func @zero64:f64() {
4+
# check: function `zero64`:
5+
# nextln: block0[]:
6+
# nextln: 0000: %0:xmm(reg)[late] = SseMovRZ
7+
# nextln: 0001: Ret %0($$xmm0)[early]
8+
9+
%c:ctrl = entry
10+
%0:f64 = fconst64 0x0
11+
return %c, %0
12+
}

0 commit comments

Comments
 (0)