diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-30 19:16:42 +0200 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-30 19:26:30 +0200 |
commit | b1e8b4f24927efc6ed68420e4f579fb20ab831a9 (patch) | |
tree | 119496bacb2758cee773138f0bd3a452c8b6ec60 /examples/variables.pipa | |
parent | efe28f579b8720ea506a4e5d24ec0290223b8745 (diff) |
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 <johnny@johnnyrichard.com>
Co-authored-by: Carlos Maniero <carlosmaniero@gmail.com>
Diffstat (limited to 'examples/variables.pipa')
-rw-r--r-- | examples/variables.pipa | 3 |
1 files changed, 2 insertions, 1 deletions
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; } |