Skip to content

Commit

Permalink
Remove redundent compiler copies in return statements
Browse files Browse the repository at this point in the history
  • Loading branch information
GsLogimaker committed Dec 12, 2023
1 parent 834f360 commit 19c8949
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions qu/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3012,6 +3012,7 @@ pub struct QuCompiler {
0,
return_type,
);
// Allocate space for return value.
let expression_reg = self.context.allocate(
return_type,
definitions,
Expand All @@ -3022,11 +3023,16 @@ pub struct QuCompiler {
expression_reg,
definitions
)?);
code.add_builder(self.cmp_copy_register(
expression_reg,
return_reg,
definitions,
)?);

if expression_reg.0 != return_reg.0 {
// Copy result to return register if its not
// already there
code.add_builder(self.cmp_copy_register(
expression_reg,
return_reg,
definitions,
)?);
}

if self.context.frames.len() == 1 {
code.add_op(Return(return_type));
Expand Down Expand Up @@ -3192,7 +3198,7 @@ pub struct QuCompiler {
let compiled = self.compile_code(&code_block, definitions)?;
self.context.close_frame();

Ok((compiled))
Ok(compiled)
}


Expand Down

0 comments on commit 19c8949

Please sign in to comment.