-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cfei: don't generate if frame size is zero #5588
Conversation
the failure looks related - it fails on local too but not on master. not flaky. will check and fix |
Hold on merging this. I vaguely remember there being a reason for it's existence. I'll update back soon. |
There's an assumption here in the spiller that the |
hmm. Some tests seem to pass with this change diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw
index b97f32603..7cdc9a8d0 100644
--- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw
+++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw
@@ -17,7 +17,7 @@ fn test_foo() {
#[test(should_revert)]
fn test_fail() {
- let contract_id = 0xa5cd13d5d8ceaa436905f361853ba278f6760da2af5061ec86fe09b8a0cf59b4;
+ let contract_id = CONTRACT_ID;
let caller = abi(MyContract, contract_id);
let result = caller.test_function {}();
assert(result == false)
@@ -25,7 +25,7 @@ fn test_fail() {
#[test]
fn test_success() {
- let contract_id = 0xa5cd13d5d8ceaa436905f361853ba278f6760da2af5061ec86fe09b8a0cf59b4;
+ let contract_id = CONTRACT_ID;
let caller = abi(MyContract, contract_id);
let result = caller.test_function {}();
assert(result == true)
So we eventually break here
We should close this if needed @vaivaswatha |
We actually want the contract ids hardcoded in those tests. They're meant to detect possible ABI breakage, using Please replace the hardcoded value and mark the PR with the |
That makes sense... but what about after the register allocation? We can move this check to CFEI(a) if a.is_zero() => return Left(vec![]),
CFEI(a) => op::CFEI::new(a.value.into()).into(), |
This is acceptable. Good idea !. |
Will follow this feedback and get back. |
the zero path is triggered quite a few times. This change effectively means we are deleting a line - which could invalidate relations between Also see sway/sway-core/src/asm_generation/finalized_asm.rs Lines 107 to 113 in 996a351
Deleting a line after this would create a problem. I confirmed that CFEI(a) if a.value == 0 => {
dbg!(("CFEI with value 0", &a));
op::NOOP::new().into()
}, instead of deleting - replacing with a NOOP would pass the current tests. Is there something that I'm missing? |
Can I get some traction here? |
Thank you @sudhackar , and apologies for the delay in my response.
But what do we gain at all by replacing it with a NOOP? The code size remains the same. @xunilrj @IGI-111 any thoughts on this?
I should've seen this coming. There's one more trick you can try. In the function |
thanks @vaivaswatha for the details - right now with this change - the IR will still generate There are no explicit test cases for this change - I'll try to add this. I have added an explicit |
Thank you @sudhackar |
…6627) ## Description This PR removes redundant `cfei/cfsi` and `cfe/cfs` instructions from the allocated abstract instruction set, if the allocated/dealocated stack size is zero. Note that, in the case of `cfei/cfsi i0` the removal does not represent an optimization, because those instructions were anyhow removed at the final bytecode generation step (see #5588). The PR in this case merely synchronizes the finalized ASM with the generated bytecode, removing potential confusion caused by existence of redundant zero stack allocations in the printed final ASM. The removal of redundant `cfei/cfsi` and `cfe/cfs` instructions _must be done on the allocated instruction set_, because the register allocation could change the original allocated/dealocated size in case of spilling. Related to #5588. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: IGI-111 <[email protected]>
Description
This small change fixes #5580 as described - only needed 1 additional change and small test fix
Ping @xunilrj
Checklist
Breaking*
orNew Feature
labels where relevant.