mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 03:01:12 +08:00
fix: 可抛算术比较位 opcode 纯标翻转,DCE 不再删副作用指令
This commit is contained in:
@@ -107,13 +107,12 @@ mod tests {
|
||||
use oxide_ir::inst::Inst;
|
||||
use oxide_ir::operand::Operand;
|
||||
|
||||
/// 线性死链:LOAD_CONST→ADD→结果丢弃,全删(剩 RETURN)。
|
||||
/// 线性死链:LOAD_CONST→MOV→结果丢弃,全删(剩 RETURN)。
|
||||
#[test]
|
||||
fn linear_dead_chain_deleted() {
|
||||
let mut f = IRFunction::new();
|
||||
f.insts.push(Inst::load_const(Operand::Reg(0), 0)); // 0: r0 = const
|
||||
f.insts
|
||||
.push(Inst::new(OpCode::ADD, Operand::Reg(1), Operand::Reg(0), Operand::Reg(0))); // 1: r1 = r0 + r0
|
||||
f.insts.push(Inst::inst_mov(Operand::Reg(1), Operand::Reg(0))); // 1: r1 = r0
|
||||
f.insts
|
||||
.push(Inst::new(OpCode::RETURN, Operand::Reg(2), Operand::None, Operand::None)); // 2: return r2
|
||||
let mut keep = vec![true; f.insts.len()];
|
||||
@@ -175,13 +174,12 @@ mod tests {
|
||||
assert_eq!(keep, vec![false, true], "死 CREATE_CLOSURE 删,RETURN 保留");
|
||||
}
|
||||
|
||||
/// 连锁迭代:写链 LOAD_CONST→ADD→LOAD_CONST 全死,逐轮删除至不动点。
|
||||
/// 连锁迭代:写链 LOAD_CONST→MOV→LOAD_CONST 全死,逐轮删除至不动点。
|
||||
#[test]
|
||||
fn chained_dead_writes_deleted_iteratively() {
|
||||
let mut f = IRFunction::new();
|
||||
f.insts.push(Inst::load_const(Operand::Reg(0), 0)); // 0: r0(ADD 读,轮 2 删)
|
||||
f.insts
|
||||
.push(Inst::new(OpCode::ADD, Operand::Reg(1), Operand::Reg(0), Operand::Reg(0))); // 1: r1(轮 1 删)
|
||||
f.insts.push(Inst::load_const(Operand::Reg(0), 0)); // 0: r0(MOV 读,轮 2 删)
|
||||
f.insts.push(Inst::inst_mov(Operand::Reg(1), Operand::Reg(0))); // 1: r1(轮 1 删)
|
||||
f.insts.push(Inst::load_const(Operand::Reg(2), 2)); // 2: r2 无人读(轮 1 删)
|
||||
f.insts
|
||||
.push(Inst::new(OpCode::RETURN, Operand::Reg(5), Operand::None, Operand::None)); // 3
|
||||
|
||||
@@ -31,18 +31,8 @@ fn run_precise(f: &mut IRFunction, after: &[&[u32]], reg_count: usize) {
|
||||
#[test]
|
||||
fn reuse_killed_dead_write_deleted() {
|
||||
let mut f = IRFunction::new();
|
||||
f.insts.push(Inst::new(
|
||||
oxide_bytecode::opcode::OpCode::ADD,
|
||||
Operand::Reg(5),
|
||||
Operand::Reg(1),
|
||||
Operand::Reg(2),
|
||||
));
|
||||
f.insts.push(Inst::new(
|
||||
oxide_bytecode::opcode::OpCode::ADD,
|
||||
Operand::Reg(5),
|
||||
Operand::Reg(3),
|
||||
Operand::Reg(4),
|
||||
));
|
||||
f.insts.push(Inst::inst_mov(Operand::Reg(5), Operand::Reg(1)));
|
||||
f.insts.push(Inst::inst_mov(Operand::Reg(5), Operand::Reg(3)));
|
||||
f.insts.push(Inst::new(
|
||||
oxide_bytecode::opcode::OpCode::RETURN,
|
||||
Operand::Reg(5),
|
||||
@@ -51,7 +41,7 @@ fn reuse_killed_dead_write_deleted() {
|
||||
));
|
||||
// inst_live_after = [{3,4}, {5}, {}]:inst0 def 5 在 live_after[0] 无 5(后写杀死)
|
||||
run_precise(&mut f, &[&[3, 4], &[5], &[]], 5);
|
||||
assert_eq!(f.insts.len(), 2, "死写(前一个 ADD)应被删");
|
||||
assert_eq!(f.insts.len(), 2, "死写(前一个 MOV)应被删");
|
||||
}
|
||||
|
||||
/// 局部死 STORE_VAR 删除(四条件全满足)。
|
||||
|
||||
Reference in New Issue
Block a user