hanazuki@ring% clang++ --version
Debian clang version 3.0-6.2 (tags/RELEASE_30/final) (based on LLVM 3.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
hanazuki@ring% clang++ -S -O2 test.cc
Last active
September 7, 2015 15:01
-
-
Save hanazuki/26e16eff59cb8c7c06fa to your computer and use it in GitHub Desktop.
INT_MIN / -1 Optimization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<limits.h> | |
int main() { | |
int x = INT_MIN; | |
int y = 1; | |
printf("%d\n", x / y); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file "test-1.cc" | |
.text | |
.globl main | |
.align 16, 0x90 | |
.type main,@function | |
main: # @main | |
.Ltmp2: | |
.cfi_startproc | |
# BB#0: | |
pushq %rbp | |
.Ltmp3: | |
.cfi_def_cfa_offset 16 | |
.Ltmp4: | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
.Ltmp5: | |
.cfi_def_cfa_register %rbp | |
movl $.L.str, %edi | |
movl $-2147483648, %esi # imm = 0xFFFFFFFF80000000 | |
xorb %al, %al | |
callq printf | |
xorl %eax, %eax | |
popq %rbp | |
ret | |
.Ltmp6: | |
.size main, .Ltmp6-main | |
.Ltmp7: | |
.cfi_endproc | |
.Leh_func_end0: | |
.type .L.str,@object # @.str | |
.section .rodata.str1.1,"aMS",@progbits,1 | |
.L.str: | |
.asciz "%d\n" | |
.size .L.str, 4 | |
.section ".note.GNU-stack","",@progbits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<limits.h> | |
int main() { | |
int x = INT_MIN; | |
int y = -1; | |
printf("%d\n", x / y); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file "test.cc" | |
.text | |
.globl main | |
.align 16, 0x90 | |
.type main,@function | |
main: # @main | |
.Ltmp2: | |
.cfi_startproc | |
# BB#0: | |
pushq %rbp | |
.Ltmp3: | |
.cfi_def_cfa_offset 16 | |
.Ltmp4: | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
.Ltmp5: | |
.cfi_def_cfa_register %rbp | |
movl $.L.str, %edi | |
xorb %al, %al | |
callq printf | |
xorl %eax, %eax | |
popq %rbp | |
ret | |
.Ltmp6: | |
.size main, .Ltmp6-main | |
.Ltmp7: | |
.cfi_endproc | |
.Leh_func_end0: | |
.type .L.str,@object # @.str | |
.section .rodata.str1.1,"aMS",@progbits,1 | |
.L.str: | |
.asciz "%d\n" | |
.size .L.str, 4 | |
.section ".note.GNU-stack","",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment