Skip to content

Instantly share code, notes, and snippets.

@mtomwing
Created September 10, 2013 22:34
Show Gist options
  • Save mtomwing/6516730 to your computer and use it in GitHub Desktop.
Save mtomwing/6516730 to your computer and use it in GitHub Desktop.
(cmpt379)thinkpad[/tmp/llvm_test] python test.py
; ModuleID = 'tut2'
define i32 @gcd(i32 %x, i32 %y) {
entry:
%tmp = icmp eq i32 %x, %y
br i1 %tmp, label %return, label %cond_false
return: ; preds = %entry
ret i32 %x
cond_false: ; preds = %entry
%tmp1 = icmp ult i32 %x, %y
br i1 %tmp1, label %cond_true, label %cond_false_2
cond_true: ; preds = %cond_false
%tmp2 = sub i32 %y, %x
%tmp3 = call i32 @gcd(i32 %x, i32 %tmp2)
ret i32 %tmp3
cond_false_2: ; preds = %cond_false
%x_sub_y = sub i32 %x, %y
%tmp4 = call i32 @gcd(i32 %x_sub_y, i32 %y)
ret i32 %tmp4
}
(cmpt379)thinkpad[/tmp/llvm_test] python test.py | llc
.file "<stdin>"
.text
.globl gcd
.align 16, 0x90
.type gcd,@function
gcd: # @gcd
.cfi_startproc
# BB#0: # %entry
pushq %rax
.Ltmp1:
.cfi_def_cfa_offset 16
movl %edi, %eax
subl %esi, %eax
jne .LBB0_1
# BB#5: # %return
movl %edi, %eax
popq %rdx
ret
.LBB0_1: # %cond_false
jae .LBB0_4
# BB#2: # %cond_true
subl %edi, %esi
jmp .LBB0_3
.LBB0_4: # %cond_false_2
movl %eax, %edi
.LBB0_3: # %cond_true
callq gcd
popq %rdx
ret
.Ltmp2:
.size gcd, .Ltmp2-gcd
.cfi_endproc
.section ".note.GNU-stack","",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment