Skip to content

Commit

Permalink
[FIX] fixing add lowering for x64 + [FIX] upsi i forgot that return c…
Browse files Browse the repository at this point in the history
…odes are u8s and not u32 ... so the top bytes would be cut off that was why i got wrong results
  • Loading branch information
Cr0a3 committed Sep 11, 2024
1 parent 9a830d6 commit b72d002
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/Target/x64/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ fn x64_lower_add(sink: &mut Vec<X64MCInstr>, 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() );

}

Expand Down
2 changes: 1 addition & 1 deletion tests/IR/add1.yl
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/IR/add2.yl
Original file line number Diff line number Diff line change
Expand Up @@ -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
# EXIT_CODE=157

0 comments on commit b72d002

Please sign in to comment.