I was reading: https://llvm.org/docs/LangRef.html#getelementptr-instruction
From what I can understand LLVM has infinite registers which raises the question, why we need store
and load
commands at all and when should we use them.
Why can't we keep everything in registers?
To make things clear, can you kindly refer to which commands are used in every line:
void example_func(int x) {
int y;
int z = 3;
int a = x;
a = 3;
x = 2;
}
void foo(int *p) { *p = 123; }
. In your example, you don't need anything at all, the function might as well be empty unless you make a debug build. See Why does clang produce inefficient asm with -O0 (for this simple floating point sum)? , and for making functions that compile to something interesting to look at, see How to remove "noise" from GCC/clang assembly output? (take args and return a value, e.g.return (x + z)*2 - 3*a;
)