Advertisement
joshudson

Untitled

Apr 4th, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. On compiling the following C code with gcc -Os -S
  2.  
  3. #include <stdio.h>
  4. extern int condition1(void);
  5. extern int condition2(void);
  6. extern int condition3(void);
  7. int main()
  8. {
  9. short c;
  10. if (condition1()) c = 3;
  11. if (condition2()) c = 4;
  12. if (condition3()) printf("%ld\n", (long)c);
  13. }
  14.  
  15.  
  16. I end up with
  17.  
  18. .file "x.c"
  19. .text
  20. .section .rodata.str1.1,"aMS",@progbits,1
  21. .LC0:
  22. .string "%ld\n"
  23. .section .text.startup,"ax",@progbits
  24. .globl main
  25. .type main, @function
  26. main:
  27. .LFB0:
  28. .cfi_startproc
  29. pushq %rbx
  30. .cfi_def_cfa_offset 16
  31. .cfi_offset 3, -16
  32. call condition1@PLT
  33. call condition2@PLT
  34. cmpl $1, %eax
  35. sbbl %ebx, %ebx
  36. addl $4, %ebx
  37. call condition3@PLT
  38. testl %eax, %eax
  39. je .L3
  40. movswq %bx, %rsi
  41. leaq .LC0(%rip), %rdi
  42. xorl %eax, %eax
  43. call printf@PLT
  44. .L3:
  45. xorl %eax, %eax
  46. popq %rbx
  47. .cfi_def_cfa_offset 8
  48. ret
  49. .cfi_endproc
  50. .LFE0:
  51. .size main, .-main
  52. .ident "GCC: (Debian 8.3.0-6) 8.3.0"
  53. .section .note.GNU-stack,"",@progbits
  54.  
  55.  
  56. The replication is currently not possible because the GCC optimizer is dumber than it used to be. Here it generates movswq where it is trivially provable that a mov will do. Since right now gcc always generates a movswq on widening operations the replication currently can't happen.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement