From b1e8b4f24927efc6ed68420e4f579fb20ab831a9 Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Sun, 30 Apr 2023 19:16:42 +0200 Subject: gas: Optimize variable reference on assembly We were moving the stack data for variable reference to another stack position ending up with two pointer to the same value. // a: i32 = 1; mov $1, -8(%rbp) // b: i32 = a; mov -8(%rbp), %rax mov %rax, -24(%rbp) mov -24(%rbp), %rax mov %rax, -16(%rbp) After this changes, we wont create a new temp space on stack if we don't need it. See bellow the example after the optimization: // a: i32 = 1; mov $1, -8(%rbp) // b: i32 = a; mov -8(%rbp), %rax mov %rax, -16(%rbp) Signed-off-by: Johnny Richard Co-authored-by: Carlos Maniero --- examples/variables.pipa | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples/variables.pipa') diff --git a/examples/variables.pipa b/examples/variables.pipa index 9c395ce..25cbd59 100644 --- a/examples/variables.pipa +++ b/examples/variables.pipa @@ -3,5 +3,6 @@ main(): i32 { b: i32 = 32; c: i32 = 2 * (b + a); d: i32 = (c - 33) + 1; - return d / 2; + e: i32 = d; + return e / 2; } -- cgit v1.2.3