Skip to content

Instantly share code, notes, and snippets.

@Jiboo
Last active September 21, 2015 15:19
Show Gist options
  • Save Jiboo/d6e839084841d39e5ab6 to your computer and use it in GitHub Desktop.
Save Jiboo/d6e839084841d39e5ab6 to your computer and use it in GitHub Desktop.

Ouput of clang -v

Apple LLVM version 7.0.0 (clang-700.0.72) Target: x86_64-apple-darwin14.5.0 Thread model: posix

Ouput of cat a.c

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
  const float a = atof(argv[1]);
  const float b = atof(argv[2]);
  const float x = a / b;
  const float y = 1 / x;
  printf("y: %f", y);
  return 0;
}

Output of clang a.c -O3 -S -emit-llvm -o -

; ModuleID = 'a.c'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.10.0"

@.str = private unnamed_addr constant [6 x i8] c"y: %f\00", align 1

; Function Attrs: nounwind ssp uwtable
define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 {
  %1 = getelementptr inbounds i8** %argv, i64 1
  %2 = load i8** %1, align 8, !tbaa !2
  %3 = tail call double @atof(i8* %2) #3
  %4 = fptrunc double %3 to float
  %5 = getelementptr inbounds i8** %argv, i64 2
  %6 = load i8** %5, align 8, !tbaa !2
  %7 = tail call double @atof(i8* %6) #3
  %8 = fptrunc double %7 to float
  %9 = fdiv float %4, %8            ; a / b
  %10 = fdiv float 1.000000e+00, %9 ; 1 / x
  %11 = fpext float %10 to double
  %12 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str, i64 0, i64 0), double %11) #3
  ret i32 0
}

; Function Attrs: nounwind readonly
declare double @atof(i8* nocapture) #1

; Function Attrs: nounwind
declare i32 @printf(i8* nocapture readonly, ...) #2

attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+ssse3,+cx16,+sse,+sse2,+sse3" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readonly "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+ssse3,+cx16,+sse,+sse2,+sse3" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #2 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+ssse3,+cx16,+sse,+sse2,+sse3" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"PIC Level", i32 2}
!1 = !{!"Apple LLVM version 7.0.0 (clang-700.0.72)"}
!2 = !{!3, !3, i64 0}
!3 = !{!"any pointer", !4, i64 0}
!4 = !{!"omnipotent char", !5, i64 0}
!5 = !{!"Simple C/C++ TBAA"}

Output of clang a.c -O3 -S -masm=intel -o -

	.section	__TEXT,__text,regular,pure_instructions
	.macosx_version_min 10, 10
	.section	__TEXT,__literal4,4byte_literals
	.align	2
LCPI0_0:
	.long	1065353216              ## float 1
	.section	__TEXT,__text,regular,pure_instructions
	.globl	_main
	.align	4, 0x90
_main:                                  ## @main
	.cfi_startproc
## BB#0:
	push	rbp
Ltmp0:
	.cfi_def_cfa_offset 16
Ltmp1:
	.cfi_offset rbp, -16
	mov	rbp, rsp
Ltmp2:
	.cfi_def_cfa_register rbp
	push	rbx
	push	rax
Ltmp3:
	.cfi_offset rbx, -24
	mov	rbx, rsi
	mov	rdi, qword ptr [rbx + 8]
	call	_atof
	cvtsd2ss	xmm0, xmm0
	movss	dword ptr [rbp - 12], xmm0 ## 4-byte Spill
	mov	rdi, qword ptr [rbx + 16]
	call	_atof
	cvtsd2ss	xmm0, xmm0
	movss	xmm1, dword ptr [rbp - 12] ## 4-byte Reload
                                        ## xmm1 = mem[0],zero,zero,zero
	divss	xmm1, xmm0
	movss	xmm0, dword ptr [rip + LCPI0_0] ## xmm0 = mem[0],zero,zero,zero
	divss	xmm0, xmm1
	cvtss2sd	xmm0, xmm0
	lea	rdi, [rip + L_.str]
	mov	al, 1
	call	_printf
	xor	eax, eax
	add	rsp, 8
	pop	rbx
	pop	rbp
	ret
	.cfi_endproc

	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"y: %f"


.subsections_via_symbols

Ouput of clang a.c -O3 -S -emit-llvm -ffast-math -o -

; ModuleID = 'a.c'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.10.0"

@.str = private unnamed_addr constant [6 x i8] c"y: %f\00", align 1

; Function Attrs: nounwind ssp uwtable
define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 {
  %1 = getelementptr inbounds i8** %argv, i64 1
  %2 = load i8** %1, align 8, !tbaa !2
  %3 = tail call double @atof(i8* %2) #3
  %4 = fptrunc double %3 to float
  %5 = getelementptr inbounds i8** %argv, i64 2
  %6 = load i8** %5, align 8, !tbaa !2
  %7 = tail call double @atof(i8* %6) #3
  %8 = fptrunc double %7 to float
  %9 = fdiv fast float %4, %8
  %10 = fdiv fast float 1.000000e+00, %9
  %11 = fpext float %10 to double
  %12 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str, i64 0, i64 0), double %11) #3
  ret i32 0
}

; Function Attrs: nounwind readonly
declare double @atof(i8* nocapture) #1

; Function Attrs: nounwind
declare i32 @printf(i8* nocapture readonly, ...) #2

attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+ssse3,+cx16,+sse,+sse2,+sse3" "unsafe-fp-math"="true" "use-soft-float"="false" }
attributes #1 = { nounwind readonly "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+ssse3,+cx16,+sse,+sse2,+sse3" "unsafe-fp-math"="true" "use-soft-float"="false" }
attributes #2 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+ssse3,+cx16,+sse,+sse2,+sse3" "unsafe-fp-math"="true" "use-soft-float"="false" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"PIC Level", i32 2}
!1 = !{!"Apple LLVM version 7.0.0 (clang-700.0.72)"}
!2 = !{!3, !3, i64 0}
!3 = !{!"any pointer", !4, i64 0}
!4 = !{!"omnipotent char", !5, i64 0}
!5 = !{!"Simple C/C++ TBAA"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment