Skip to content

Instantly share code, notes, and snippets.

@milesfrain
Created October 7, 2019 20:58
Show Gist options
  • Save milesfrain/12222c241f33d3527b53b98ee53ae457 to your computer and use it in GitHub Desktop.
Save milesfrain/12222c241f33d3527b53b98ee53ae457 to your computer and use it in GitHub Desktop.
Int vs UInt Performance
julia> @code_llvm debuginfo=:none runbench_expand(UInt)
define i64 @julia_runbench_expand_17321(%jl_value_t addrspace(10)*) {
top:
br label %L2
L2: ; preds = %L30, %top
%value_phi = phi i64 [ 0, %top ], [ %value_phi6, %L30 ]
%value_phi1 = phi i64 [ 1, %top ], [ %3, %L30 ]
br label %pass
L6: ; preds = %pass
%1 = add nuw nsw i64 %value_phi416, 1
br label %pass
L30: ; preds = %pass
%2 = icmp eq i64 %value_phi1, 1000
%3 = add nuw nsw i64 %value_phi1, 1
br i1 %2, label %L42, label %L2
L42: ; preds = %L30
ret i64 %value_phi6
pass: ; preds = %L6, %L2
%value_phi416 = phi i64 [ 1, %L2 ], [ %1, %L6 ]
%value_phi315 = phi i64 [ %value_phi, %L2 ], [ %value_phi6, %L6 ]
%4 = urem i64 %value_phi1, %value_phi416
%5 = icmp eq i64 %4, 0
%6 = add nuw nsw i64 %value_phi416, %value_phi1
%7 = sub nsw i64 %6, %4
%value_phi1.pn = select i1 %5, i64 %value_phi1, i64 %7
%value_phi6 = add i64 %value_phi1.pn, %value_phi315
%8 = icmp eq i64 %value_phi416, 1000
br i1 %8, label %L30, label %L6
}
julia> @code_native debuginfo=:none runbench_expand(UInt)
.text
movl $1, %r9d
xorl %esi, %esi
movl $2, %r8d
nop
L16:
movq %r8, %r10
movl $999, %ecx # imm = 0x3E7
movl $1, %edi
movq %r9, %rax
orq %rdi, %rax
shrq $32, %rax
jne L72
jmp L96
nopl (%rax,%rax)
L48:
addq $1, %rdi
addq $-1, %rcx
addq $1, %r10
movq %r9, %rax
orq %rdi, %rax
shrq $32, %rax
je L96
L72:
xorl %edx, %edx
movq %r9, %rax
divq %rdi
jmp L103
nopw %cs:(%rax,%rax)
L96:
xorl %edx, %edx
movl %r9d, %eax
divl %edi
L103:
movq %r10, %rax
subq %rdx, %rax
testq %rdx, %rdx
cmoveq %r9, %rax
addq %rax, %rsi
testq %rcx, %rcx
jne L48
addq $1, %r8
cmpq $1000, %r9 # imm = 0x3E8
leaq 1(%r9), %r9
jne L16
movq %rsi, %rax
retq
nopw %cs:(%rax,%rax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment