ZJIT: Avoid splitting add_into/sub_into for x86_64 (#14177)

* ZJIT: Avoid splitting add_into/sub_into

* Require add_into/sub_into to take a Reg
This commit is contained in:
Takashi Kokubun 2025-08-12 09:54:50 -07:00 committed by GitHub
parent c5c894c6e4
commit e26ab5dbf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 9 deletions

View file

@ -1889,9 +1889,9 @@ impl Assembler {
out
}
pub fn add_into(&mut self, left: Opnd, right: Opnd) -> Opnd {
pub fn add_into(&mut self, left: Opnd, right: Opnd) {
assert!(matches!(left, Opnd::Reg(_)), "Destination of add_into must be Opnd::Reg, but got: {left:?}");
self.push_insn(Insn::Add { left, right, out: left });
left
}
#[must_use]
@ -2233,10 +2233,9 @@ impl Assembler {
out
}
pub fn sub_into(&mut self, left: Opnd, right: Opnd) -> Opnd {
let out = self.sub(left, right);
self.mov(left, out);
out
pub fn sub_into(&mut self, left: Opnd, right: Opnd) {
assert!(matches!(left, Opnd::Reg(_)), "Destination of sub_into must be Opnd::Reg, but got: {left:?}");
self.push_insn(Insn::Sub { left, right, out: left });
}
#[must_use]

View file

@ -197,9 +197,15 @@ impl Assembler
}
},
// We have to load memory operands to avoid corrupting them
(Opnd::Mem(_) | Opnd::Reg(_), _) => {
(Opnd::Mem(_), _) => {
*left = asm.load(*left);
},
// We have to load register operands to avoid corrupting them
(Opnd::Reg(_), _) => {
if *left != *out {
*left = asm.load(*left);
}
},
// The first operand can't be an immediate value
(Opnd::UImm(_), _) => {
*left = asm.load(*left);
@ -1164,7 +1170,21 @@ mod tests {
asm.mov(CFP, sp); // should be merged to add
asm.compile_with_num_regs(&mut cb, 1);
assert_eq!(format!("{:x}", cb), "4983c540");
assert_disasm!(cb, "4983c540", {"
0x0: add r13, 0x40
"});
}
#[test]
fn test_add_into() {
let (mut asm, mut cb) = setup_asm();
asm.add_into(CFP, Opnd::UImm(0x40));
asm.compile_with_num_regs(&mut cb, 1);
assert_disasm!(cb, "4983c540", {"
0x0: add r13, 0x40
"});
}
#[test]
@ -1175,7 +1195,21 @@ mod tests {
asm.mov(CFP, sp); // should be merged to add
asm.compile_with_num_regs(&mut cb, 1);
assert_eq!(format!("{:x}", cb), "4983ed40");
assert_disasm!(cb, "4983ed40", {"
0x0: sub r13, 0x40
"});
}
#[test]
fn test_sub_into() {
let (mut asm, mut cb) = setup_asm();
asm.sub_into(CFP, Opnd::UImm(0x40));
asm.compile_with_num_regs(&mut cb, 1);
assert_disasm!(cb, "4983ed40", {"
0x0: sub r13, 0x40
"});
}
#[test]