Toying around with clang
, I compiled a C program containing this line:
printf("%s
", argv[0]);
When compiling without optimization, the assembly output called printf
after setting up the registers:
movq (%rcx), %rsi
movq %rax, %rdi
movb $0, %al
callq _printf
I tried compiling with clang -O2
. The printf
call was replaced to a puts
call:
movq (%rsi), %rdi
callq _puts
While this makes perfect sense in this case, it raises two questions:
- How often does function call substitution happen in optimized compilation? Is this frequent or is stdio an exception?
- Could I write compiler optimizations for my own libraries? How would I do that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…