[llvm-dev] How to understand "tail" call?

Peng Yu via llvm-dev
2019-02-06T18:04:12Z

Hi,

    %1 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds
([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 10)
    %2 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds
([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 10)

When I use -O2 to compile the following C code, I will get the above
IR code. I don't understand the explanation of tail-call-optimization
in the langref. Could anybody help me understand what tail call means?
Thanks.

https://llvm.org/docs/CodeGenerator.html#tail-call-optimization

#include <stdio.h>

int main(void) {
    const int local = 10;
    int *ptr = (int*) &local;
    printf("Initial value of local : %d \n", local);
    *ptr = 100;
    printf("Modified value of local: %d \n", local);
    return 0;
}

--
Regards,
Peng