Conversation

A question for the compiler nerds: if I have a (C) function that uses a lot of intermediate local structs or fixed size arrays that are not long-lived inside that function, can I trust the C compiler to re-use the memory?
1
E.g. void compute(int init) { int a[100]; f(a,100,init); // compute a[] from init int b[100]; g(a,b,100); // compute b[] from a[] // a is no longer referenced after this, so c can use a's storage int c[100]; g(b,c,100); // compute c[] from b[] }
1
Basically I want to be lazy and leave this to the lower level compiler (C compiler, or LLVM), and I do not want to generate my own local buffer management code. So essentially, my generated code is SSA at the buffer level, where low level compiler would figure out buffer re-use.
1
Replying to
TIL LLVM does "stack coloring"
Quote Tweet
Thought: LLVM has a late stack coloring pass that detects non-interfering ranges of the stack based on liveness ranges to save stack space. What if it could detect two stack slots "bridged" by a memcpy and assigned them the same slot, and then delete the memcpy?
Show this thread