Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- On compiling the following C code with gcc -Os -S
- #include <stdio.h>
- extern int condition1(void);
- extern int condition2(void);
- extern int condition3(void);
- int main()
- {
- short c;
- if (condition1()) c = 3;
- if (condition2()) c = 4;
- if (condition3()) printf("%ld\n", (long)c);
- }
- I end up with
- .file "x.c"
- .text
- .section .rodata.str1.1,"aMS",@progbits,1
- .LC0:
- .string "%ld\n"
- .section .text.startup,"ax",@progbits
- .globl main
- .type main, @function
- main:
- .LFB0:
- .cfi_startproc
- pushq %rbx
- .cfi_def_cfa_offset 16
- .cfi_offset 3, -16
- call condition1@PLT
- call condition2@PLT
- cmpl $1, %eax
- sbbl %ebx, %ebx
- addl $4, %ebx
- call condition3@PLT
- testl %eax, %eax
- je .L3
- movswq %bx, %rsi
- leaq .LC0(%rip), %rdi
- xorl %eax, %eax
- call printf@PLT
- .L3:
- xorl %eax, %eax
- popq %rbx
- .cfi_def_cfa_offset 8
- ret
- .cfi_endproc
- .LFE0:
- .size main, .-main
- .ident "GCC: (Debian 8.3.0-6) 8.3.0"
- .section .note.GNU-stack,"",@progbits
- 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