diff --git a/src/Target/x64/lower.rs b/src/Target/x64/lower.rs index 39d2f03e..f514f2d8 100644 --- a/src/Target/x64/lower.rs +++ b/src/Target/x64/lower.rs @@ -71,8 +71,11 @@ fn x64_lower_add(sink: &mut Vec, instr: &MachineInstr) { }, }; - sink.push( X64MCInstr::with2(Mnemonic::Mov, out.clone(), op1).into() ); - sink.push( X64MCInstr::with2(Mnemonic::Add, out, op2).into() ); + let tmp = || Operand::Reg(x64Reg::Rax.sub_ty(instr.meta)); + + sink.push( X64MCInstr::with2(Mnemonic::Mov, tmp(), op1).into() ); + sink.push( X64MCInstr::with2(Mnemonic::Add, tmp(), op2).into() ); + sink.push( X64MCInstr::with2(Mnemonic::Mov, out, tmp()).into() ); } diff --git a/tests/IR/add1.yl b/tests/IR/add1.yl index b6340533..62bf3421 100644 --- a/tests/IR/add1.yl +++ b/tests/IR/add1.yl @@ -1,5 +1,5 @@ # RUN: -cargo run -p ylc -- -in=%s -o=out.o -asm-clr +cargo run -p ylc -- -in=%s -o=out.o gcc out.o -o a.exe ./a.exe # IN: diff --git a/tests/IR/add2.yl b/tests/IR/add2.yl index ce4d902d..f9a6e398 100644 --- a/tests/IR/add2.yl +++ b/tests/IR/add2.yl @@ -6,9 +6,9 @@ gcc out.o -o a.exe define i32 @main() { entry: %0 = i32 134 - %1 = add i32 %0, 523 + %1 = add i32 %0, 23 ret i32 %1 } -# EXIT_CODE=657 \ No newline at end of file +# EXIT_CODE=157 \ No newline at end of file