From baa70d3f1272c2cbb208ca17115dc54b7d31af5c Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 16 Nov 2024 10:16:35 +0100 Subject: [PATCH] removing needless copy into ret register --- lang/src/son/hbvm/my_regalloc.rs | 8 ++++---- lang/tests/son_tests_different_function_destinations.txt | 4 +--- lang/tests/son_tests_null_check_in_the_loop.txt | 5 ++--- .../tests/son_tests_null_check_returning_small_global.txt | 4 +--- lang/tests/son_tests_nullable_structure.txt | 3 +-- lang/tests/son_tests_nullable_types.txt | 4 +--- lang/tests/son_tests_optional_from_eca.txt | 5 ++--- .../son_tests_overwrite_aliasing_overoptimization.txt | 3 +-- lang/tests/son_tests_returning_global_struct.txt | 3 +-- lang/tests/son_tests_returning_optional_issues.txt | 3 +-- lang/tests/son_tests_scheduling_block_did_dirty.txt | 3 +-- lang/tests/son_tests_small_struct_bitcast.txt | 3 +-- lang/tests/son_tests_storing_into_nullable_struct.txt | 3 +-- .../son_tests_struct_return_from_module_function.txt | 5 +---- lang/tests/son_tests_structs.txt | 3 +-- lang/tests/son_tests_wide_ret.txt | 4 +--- 16 files changed, 21 insertions(+), 42 deletions(-) diff --git a/lang/src/son/hbvm/my_regalloc.rs b/lang/src/son/hbvm/my_regalloc.rs index 1ef67b3f..20303e67 100644 --- a/lang/src/son/hbvm/my_regalloc.rs +++ b/lang/src/son/hbvm/my_regalloc.rs @@ -238,11 +238,11 @@ impl HbvmBackend { }; } - if node.ty.loc(tys) == Loc::Stack - && let Some(PLoc::Reg(r, ..) | PLoc::WideReg(r, ..) | PLoc::Ref(r, ..)) = - ret - { + if node.ty.loc(tys) == Loc::Stack { alloc_buf.push(atr(*node.inputs.last().unwrap())); + } + + if let Some(PLoc::Ref(r, ..)) = ret { self.emit(instrs::cp(r, *alloc_buf.last().unwrap())) } } diff --git a/lang/tests/son_tests_different_function_destinations.txt b/lang/tests/son_tests_different_function_destinations.txt index 436e3b21..5e6a775c 100644 --- a/lang/tests/son_tests_different_function_destinations.txt +++ b/lang/tests/son_tests_different_function_destinations.txt @@ -2,7 +2,6 @@ main: ADDI64 r254, r254, -160d ST r31, r254, 80a, 80h LRA r32, r0, :glob_stru - CP r1, r32 JAL r31, r0, :new_stru ST r1, r32, 0a, 16h CP r33, r0 @@ -65,7 +64,6 @@ main: JMP :7 3: MULI64 r39, r32, 16d ADD64 r39, r37, r39 - CP r1, r39 JAL r31, r0, :new_stru ST r1, r39, 0a, 16h ADD64 r32, r32, r35 @@ -83,6 +81,6 @@ new_stru: LD r32, r254, 16a, 8h ADDI64 r254, r254, 24d JALA r0, r31, 0a -code size: 797 +code size: 791 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_null_check_in_the_loop.txt b/lang/tests/son_tests_null_check_in_the_loop.txt index 86070811..333a3680 100644 --- a/lang/tests/son_tests_null_check_in_the_loop.txt +++ b/lang/tests/son_tests_null_check_in_the_loop.txt @@ -2,8 +2,7 @@ main: ADDI64 r254, r254, -38d ST r31, r254, 6a, 32h ADDI64 r32, r254, 0d - 2: CP r1, r32 - JAL r31, r0, :return_fn + 2: JAL r31, r0, :return_fn ST r1, r32, 0a, 6h LD r33, r254, 0a, 1h ANDI r33, r33, 255d @@ -30,6 +29,6 @@ return_fn: LD r32, r254, 6a, 16h ADDI64 r254, r254, 22d JALA r0, r31, 0a -code size: 317 +code size: 314 ret: 1 status: Ok(()) diff --git a/lang/tests/son_tests_null_check_returning_small_global.txt b/lang/tests/son_tests_null_check_returning_small_global.txt index 750619ec..98a79a18 100644 --- a/lang/tests/son_tests_null_check_returning_small_global.txt +++ b/lang/tests/son_tests_null_check_returning_small_global.txt @@ -4,7 +4,6 @@ foo: ADDI64 r32, r254, 64d LRA r33, r0, :some_file CP r3, r33 - CP r1, r32 JAL r31, r0, :get ST r1, r32, 0a, 16h LD r33, r254, 64a, 1h @@ -63,7 +62,6 @@ main: ADDI64 r254, r254, -48d ST r31, r254, 16a, 32h ADDI64 r32, r254, 0d - CP r1, r32 JAL r31, r0, :foo ST r1, r32, 0a, 16h LD r33, r254, 0a, 1h @@ -77,6 +75,6 @@ main: 1: LD r31, r254, 16a, 32h ADDI64 r254, r254, 48d JALA r0, r31, 0a -code size: 771 +code size: 765 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_nullable_structure.txt b/lang/tests/son_tests_nullable_structure.txt index 828effa1..9b7407ac 100644 --- a/lang/tests/son_tests_nullable_structure.txt +++ b/lang/tests/son_tests_nullable_structure.txt @@ -7,7 +7,6 @@ main: CP r1, r33 JAL r31, r0, :returner_bn ADDI64 r34, r254, 0d - CP r1, r34 JAL r31, r0, :returner_cn ST r1, r34, 0a, 2h LD r33, r254, 2a, 1h @@ -62,6 +61,6 @@ returner_fn: LD r32, r254, 0a, 8h ADDI64 r254, r254, 8d JALA r0, r31, 0a -code size: 566 +code size: 563 ret: 1 status: Ok(()) diff --git a/lang/tests/son_tests_nullable_types.txt b/lang/tests/son_tests_nullable_types.txt index db311b25..ddfbacd3 100644 --- a/lang/tests/son_tests_nullable_types.txt +++ b/lang/tests/son_tests_nullable_types.txt @@ -55,7 +55,6 @@ main: CP r1, r32 JMP :3 9: ADDI64 r33, r254, 40d - CP r1, r33 JAL r31, r0, :new_foo ST r1, r33, 0a, 16h LD r37, r254, 40a, 8h @@ -68,7 +67,6 @@ main: LD r2, r33, 0a, 16h JAL r31, r0, :use_foo ADDI64 r33, r254, 0d - CP r1, r33 JAL r31, r0, :no_foo ST r1, r33, 0a, 16h JAL r31, r0, :decide @@ -150,6 +148,6 @@ use_foo: CP r0, r4 ADDI64 r254, r254, 16d JALA r0, r31, 0a -code size: 1252 +code size: 1246 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_optional_from_eca.txt b/lang/tests/son_tests_optional_from_eca.txt index 633b996f..300709ec 100644 --- a/lang/tests/son_tests_optional_from_eca.txt +++ b/lang/tests/son_tests_optional_from_eca.txt @@ -6,7 +6,6 @@ main: CP r4, r0 CP r5, r0 CP r6, r0 - CP r1, r13 ECA ST r1, r13, 0a, 16h LD r14, r254, 0a, 1h @@ -19,6 +18,6 @@ main: ADDI64 r254, r254, 32d JALA r0, r31, 0a unknown ecall: 0 -code size: 153 +code size: 150 ret: 0 -status: Ok(()) +status: Err(Unreachable) diff --git a/lang/tests/son_tests_overwrite_aliasing_overoptimization.txt b/lang/tests/son_tests_overwrite_aliasing_overoptimization.txt index 99050dfb..bcc7b93b 100644 --- a/lang/tests/son_tests_overwrite_aliasing_overoptimization.txt +++ b/lang/tests/son_tests_overwrite_aliasing_overoptimization.txt @@ -7,7 +7,6 @@ main: LI64 r34, 4d ST r34, r254, 0a, 8h ST r33, r254, 8a, 8h - CP r1, r32 JAL r31, r0, :opaque ST r1, r32, 0a, 16h LD r34, r254, 8a, 8h @@ -31,6 +30,6 @@ opaque: LD r32, r254, 16a, 16h ADDI64 r254, r254, 32d JALA r0, r31, 0a -code size: 339 +code size: 336 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_returning_global_struct.txt b/lang/tests/son_tests_returning_global_struct.txt index 3cf09ac2..d6b621ef 100644 --- a/lang/tests/son_tests_returning_global_struct.txt +++ b/lang/tests/son_tests_returning_global_struct.txt @@ -2,7 +2,6 @@ main: ADDI64 r254, r254, -60d ST r31, r254, 4a, 56h ADDI64 r32, r254, 0d - CP r1, r32 JAL r31, r0, :random_color ST r1, r32, 0a, 4h LD r34, r254, 0a, 1h @@ -28,6 +27,6 @@ random_color: LD r32, r254, 0a, 8h ADDI64 r254, r254, 8d JALA r0, r31, 0a -code size: 295 +code size: 292 ret: 1020 status: Ok(()) diff --git a/lang/tests/son_tests_returning_optional_issues.txt b/lang/tests/son_tests_returning_optional_issues.txt index 2edae21b..93effff6 100644 --- a/lang/tests/son_tests_returning_optional_issues.txt +++ b/lang/tests/son_tests_returning_optional_issues.txt @@ -15,7 +15,6 @@ main: ADDI64 r254, r254, -48d ST r31, r254, 16a, 32h ADDI64 r32, r254, 0d - CP r1, r32 JAL r31, r0, :get_format ST r1, r32, 0a, 16h LD r33, r254, 0a, 1h @@ -29,6 +28,6 @@ main: 1: LD r31, r254, 16a, 32h ADDI64 r254, r254, 48d JALA r0, r31, 0a -code size: 304 +code size: 301 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_scheduling_block_did_dirty.txt b/lang/tests/son_tests_scheduling_block_did_dirty.txt index 63916066..5cc1da21 100644 --- a/lang/tests/son_tests_scheduling_block_did_dirty.txt +++ b/lang/tests/son_tests_scheduling_block_did_dirty.txt @@ -17,7 +17,6 @@ main: ST r31, r254, 16a, 24h ADDI64 r32, r254, 0d CP r3, r0 - CP r1, r32 JAL r31, r0, :constructor ST r1, r32, 0a, 16h LD r31, r254, 16a, 24h @@ -35,6 +34,6 @@ opaque: LD r32, r254, 0a, 16h ADDI64 r254, r254, 16d JALA r0, r31, 0a -code size: 330 +code size: 327 ret: 255 status: Ok(()) diff --git a/lang/tests/son_tests_small_struct_bitcast.txt b/lang/tests/son_tests_small_struct_bitcast.txt index 72c55b93..50a97115 100644 --- a/lang/tests/son_tests_small_struct_bitcast.txt +++ b/lang/tests/son_tests_small_struct_bitcast.txt @@ -5,7 +5,6 @@ main: ADDI64 r33, r254, 0d LD r32, r32, 0a, 4h CP r2, r32 - CP r1, r33 JAL r31, r0, :u32_to_color ST r1, r33, 0a, 4h LD r32, r254, 0a, 1h @@ -35,6 +34,6 @@ u32_to_u32: LD r32, r254, 0a, 8h ADDI64 r254, r254, 8d JALA r0, r31, 0a -code size: 332 +code size: 329 ret: 255 status: Ok(()) diff --git a/lang/tests/son_tests_storing_into_nullable_struct.txt b/lang/tests/son_tests_storing_into_nullable_struct.txt index 00545ee7..23eccd9c 100644 --- a/lang/tests/son_tests_storing_into_nullable_struct.txt +++ b/lang/tests/son_tests_storing_into_nullable_struct.txt @@ -28,7 +28,6 @@ main: JAL r31, r0, :do_stuff CP r32, r1 ADDI64 r33, r254, 0d - CP r1, r33 JAL r31, r0, :optional ST r1, r33, 0a, 16h LD r33, r254, 0a, 1h @@ -76,6 +75,6 @@ optionala: LD r32, r254, 48a, 32h ADDI64 r254, r254, 80d JALA r0, r31, 0a -code size: 673 +code size: 670 ret: 100 status: Ok(()) diff --git a/lang/tests/son_tests_struct_return_from_module_function.txt b/lang/tests/son_tests_struct_return_from_module_function.txt index 42dd96cb..1d38b391 100644 --- a/lang/tests/son_tests_struct_return_from_module_function.txt +++ b/lang/tests/son_tests_struct_return_from_module_function.txt @@ -15,15 +15,12 @@ main: ADDI64 r254, r254, -96d ST r31, r254, 48a, 48h ADDI64 r32, r254, 32d - CP r1, r32 JAL r31, r0, :foo ST r1, r32, 0a, 16h ADDI64 r33, r254, 16d - CP r1, r33 JAL r31, r0, :foo ST r1, r33, 0a, 16h ADDI64 r34, r254, 0d - CP r1, r34 JAL r31, r0, :foo ST r1, r34, 0a, 16h LD r33, r254, 24a, 4h @@ -39,6 +36,6 @@ main: LD r31, r254, 48a, 48h ADDI64 r254, r254, 96d JALA r0, r31, 0a -code size: 393 +code size: 384 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_structs.txt b/lang/tests/son_tests_structs.txt index 325014bf..3b354eba 100644 --- a/lang/tests/son_tests_structs.txt +++ b/lang/tests/son_tests_structs.txt @@ -7,7 +7,6 @@ main: LI64 r32, 3d ST r32, r254, 24a, 8h ADDI64 r34, r254, 0d - CP r1, r34 LD r3, r33, 0a, 16h JAL r31, r0, :odher_pass ST r1, r34, 0a, 16h @@ -41,6 +40,6 @@ pass: LD r32, r254, 0a, 8h ADDI64 r254, r254, 8d JALA r0, r31, 0a -code size: 390 +code size: 387 ret: 4 status: Ok(()) diff --git a/lang/tests/son_tests_wide_ret.txt b/lang/tests/son_tests_wide_ret.txt index 21e5603f..5a354e8b 100644 --- a/lang/tests/son_tests_wide_ret.txt +++ b/lang/tests/son_tests_wide_ret.txt @@ -4,7 +4,6 @@ main: ADDI64 r32, r254, 0d CP r3, r0 CP r4, r0 - CP r1, r32 JAL r31, r0, :maina ST r1, r32, 0a, 16h LD r34, r254, 12a, 1h @@ -21,7 +20,6 @@ maina: CP r0, r3 CP r0, r4 ADDI64 r32, r254, 16d - CP r1, r32 JAL r31, r0, :small_struct ST r1, r32, 0a, 4h ADDI64 r33, r254, 0d @@ -57,6 +55,6 @@ small_struct: LD r32, r254, 4a, 8h ADDI64 r254, r254, 12d JALA r0, r31, 0a -code size: 597 +code size: 591 ret: 2 status: Ok(())