Profile photo for Rustam Muginov

You can always check it yourself.

Take the very simple code:

  1. int foo1(int x) { 
  2. return x * 2; 
  3. } 
  4. int foo2(int x) { 
  5. return x << 1; 
  6. } 

Compile it and see the result of clang generated optimized code, for x86_64:

  1. _foo1: 
  2. 0000000000000000 pushq %rbp 
  3. 0000000000000001 movq %rsp, %rbp 
  4. 0000000000000004 leal _foo1(%rdi,%rdi), %eax 
  5. 0000000000000007 popq %rbp 
  6. 0000000000000008 retq 
  7. 0000000000000009 nopl _foo1(%rax) 
  8. _foo2: 
  9. 0000000000000010 pushq %rbp 
  10. 0000000000000011 movq %rsp, %rbp 
  11. 0000000000000014 leal _foo1(%rdi,%rdi), %eax 
  12. 0000000000000017 popq %rbp 
  13. 0000000000000018 retq 

The code of these two functions is 100% the same (disregard the “_foo1” symbol disassembler used to show zero offset, and the alignment no-op at address 0x0009)

So do not waste your time trying to be smarter than compiler. Just write clean and readable code.

View 21 other answers to this question
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025