-
Notifications
You must be signed in to change notification settings - Fork 171
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
Inefficient String Concatenation When Compiling C to WASM/WAT #389
Comments
It's probably a target-independent optimization in upstream LLVM doing this. Are you compiling with -O2? If so, it may be worth trying with -Oz or -Os instead. |
Hi, thanks for your suggestion! @sunfishcode clang -O0 --target=wasm32-wasi -o b_o.wasm b.c ; wasm2wat b_o.wasm -o b_o.wat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've encountered an issue while compiling C code to WASM, and subsequently converting it to WAT. The issue pertains to the way string concatenation is handled in the WAT output.
b.zip
Here's a snippet of my C source code snippet:
After compiling this C code to WASM and then converting it to WAT, I expected to find both strings 'Hello, ' and 'World!' in the data section of the WAT file. However, I could only find 'Hello, ' in the data section.
Instead of finding 'World!' as a contiguous string in the data section, I found it concatenated character by character in the function body, like so:
I'm puzzled by this behavior. Storing the strings in the data section seems to be a more efficient approach than concatenating them character by character in the function body. Is there a specific reason for this implementation? Could this be an optimization issue with the compiler?
The text was updated successfully, but these errors were encountered: