-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Exhaustive stack usage #43598
Comments
Yes, lifetime markers are missing. |
Yeah, I think it's a known issue that we don't emit them for temporaries. |
Adding lifetime markers for the temp from EmitAnyExprToTemp(E) in EmitCallArg brings the stack size to 16424. |
That should be a fairly localized change that doesn't need a solution to the more general issue with temporaries. Did you have a patch for it, or did you just try adding lifetime markers to the IR? |
The issue affects users of the stackful coroutines by adding very significant memory overhead (each of the thousands coroutines becomes multiple times bigger). We'd appreciate a fix for 10.0. |
Seems like Francis has a patch? |
Sorry about the delay. I had a quick patch but it seems like Erik addressed this in https://reviews.llvm.org/D74094. I see that this has been reverted due to a ppc failure. I locally re-applied the patch and I see the function using only 16424 bytes. |
I've revived https://reviews.llvm.org/D74094; let's see what issues with that approach may persist, if any. |
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: #38157 Link: #41896 Link: #43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
relanded as https://reviews.llvm.org/rGe698695fbbf62e6676f8907665187f2d2c4d814b in clang-18. |
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
The latest C23 draft § 6.2.4 Storage durations of objects
Speaking more with @AaronBallman , Aaron found https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1285.htm introduced the current wording into c11. https://wiki.sei.cmu.edu/confluence/display/c/EXP35-C.+Do+not+modify+objects+with+temporary+lifetime talks more about this. I'm kind of hung up on the specific wording: EDIT: sorry, I should file a new bug about C. https://web.archive.org/web/20231010182056/https://yarchive.net/comp/struct_return.html talks more about this in regards to arrays within the returned struct. |
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
I noticed this today when using coroutines. This function:
allocates 88 bytes for storage of its stack, but this one:
allocates 408 bytes for its coroutine stack. In 2019 a similar issue was fixed in the Rust compiler resulting in significant space savings: rust-lang/rust#60187 I'm interested in helping contribute to a fix here. Is https://reviews.llvm.org/D74094 the latest discussion on this? |
That's the latest discussion I'm aware of. |
Extended Description
Consider the following example:
With
-std=c++11 -O2
flags Clang uses 32768 bytes of stack, GCC uses 16392 bytes.Note that adding additional
t.Extend(static_cast<test&&>(t));
results in stack usage growth for Clang, while GCC keeps using only 16392 bytes.Godbolt playground: https://godbolt.org/z/MdaNfa
The text was updated successfully, but these errors were encountered: