-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
introduce a "try" ZIR and AIR instruction #11783
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
Conversation
Implemented for Wasm backend in 7fb9650 |
This was a pretty big win for the C backend:
|
Some stats on those changes for the Wasm backend:
This means an improvement of |
Some stats on those changes for the x64 backend:
This means an improvement of 12645 bytes in total. |
This introduces two ZIR instructions: * `try` * `try_inline` This is part of an effort to implement #11772.
Implements semantic analysis for the new try/try_inline ZIR instruction. Adds the new try/try_ptr AIR instructions and implements them for the LLVM backend. Fixes not calling rvalue() for tryExpr in AstGen. This is part of an effort to implement #11772.
* Introduce "_ptr" variants of ZIR try instruction to disallow constructs such as `try` on a pointer value instead of an error union value. * Disable the "_inline" variants of the ZIR try instruction for now because we are out of ZIR tags. I will free up some space in an independent commit. * AstGen: fix tryExpr calling rvalue() on ResultLoc.ref
This function took is_ptr: bool and then branched on it three times. Now, instead, each implementation does no branching and the logic is easier to follow, both for maintainers and compilers. I also fixed a bug with TryPtr not ensuring enough capacity in the extra array.
Reduction in size for ARM (behavior test binary): master: 1398205 bytes reduction: 53253 bytes = 0.0380866897200339 (about 3.8%) |
b3344f8
to
a34f3ff
Compare
Implements #11772.
Merge Checklist:
riscv64not covered by CI testssparc64not covered by CI testsAnalysis
Note: master branch at time of writing is e498fb1.
It did not close the bloat gap (#11498). File size stats after this change:
So it seems that this branch produces a slightly smaller executable (a delta of 25 KB) in both cases, but did not change the relative size difference.
However it did have a small improvement on how long it took to build in release mode with LLVM:
Here's the measurement that should probably be used to decide whether this patch is overall an improvement:
I keep getting
error: AccessDenied
intermittently when running stage3 and I have not diagnosed it yet. This is tracked in #11450. It's unfortunate here because the stage3 measurement is what we are most interested in.Here's the same measurement but with
-Denable-llvm
which apparently does not trip the "access denied" error:Finally, let's look at perf of debug builds:
Looking at the optimized LLVM IR, did
buildOutputType
get the desired cleanup pattern?❌ no
Conclusion
Overall, this seems to have had a small, but noticeable impact. Given that it produces better runtime code for a common zig syntax in debug builds, I am inclined to press forward with this change.