Skip to content

Instantly share code, notes, and snippets.

@simonster
Created August 3, 2013 20:08
Show Gist options
  • Save simonster/6147815 to your computer and use it in GitHub Desktop.
Save simonster/6147815 to your computer and use it in GitHub Desktop.
Julia vectorization
julia> f(x) = for i = 1:length(x); @inbounds x[i] *= 2; end
# methods for generic function f
f(x) at none:1
julia> disassemble(f, (Matrix{Float64},))
define void @julia_f(i8**) {
top:
%1 = getelementptr i8** %0, i64 2, !dbg !3364
%2 = load i8** %1, align 8, !dbg !3364
%3 = icmp slt i8* %2, inttoptr (i64 1 to i8*), !dbg !3369
br i1 %3, label %L2, label %if.lr.ph, !dbg !3369
if.lr.ph: ; preds = %top
%4 = ptrtoint i8* %2 to i64, !dbg !3364
%5 = getelementptr i8** %0, i64 1, !dbg !3364
%6 = load i8** %5, align 8, !dbg !3364
%7 = bitcast i8* %6 to double*, !dbg !3370
%8 = icmp sgt i64 %4, 1
%smax = select i1 %8, i64 %4, i64 1
%n.mod.vf = urem i64 %smax, 6
%cmp.zero = icmp eq i64 %smax, %n.mod.vf
br i1 %cmp.zero, label %middle.block, label %vector.ph
vector.ph: ; preds = %if.lr.ph
%n.vec = sub i64 %smax, %n.mod.vf
%end.idx.rnd.down = add i64 %n.vec, 1
br label %vector.body
vector.body: ; preds = %vector.body, %vector.ph
%index = phi i64 [ 1, %vector.ph ], [ %index.next, %vector.body ]
%9 = add i64 %index, -1
%10 = getelementptr double* %7, i64 %9, !dbg !3370
%11 = bitcast double* %10 to <2 x double>*
%wide.load = load <2 x double>* %11, align 8
%.sum = add i64 %index, 1
%12 = getelementptr double* %7, i64 %.sum
%13 = bitcast double* %12 to <2 x double>*
%wide.load6 = load <2 x double>* %13, align 8
%.sum13 = add i64 %index, 3
%14 = getelementptr double* %7, i64 %.sum13
%15 = bitcast double* %14 to <2 x double>*
%wide.load7 = load <2 x double>* %15, align 8
%16 = fmul <2 x double> %wide.load, <double 2.000000e+00, double 2.000000e+00>
%17 = fmul <2 x double> %wide.load6, <double 2.000000e+00, double 2.000000e+00>
%18 = fmul <2 x double> %wide.load7, <double 2.000000e+00, double 2.000000e+00>
store <2 x double> %16, <2 x double>* %11, align 8
store <2 x double> %17, <2 x double>* %13, align 8
store <2 x double> %18, <2 x double>* %15, align 8
%index.next = add i64 %index, 6
%19 = icmp eq i64 %index.next, %end.idx.rnd.down
br i1 %19, label %middle.block, label %vector.body
middle.block: ; preds = %vector.body, %if.lr.ph
%resume.val = phi i64 [ 1, %if.lr.ph ], [ %end.idx.rnd.down, %vector.body ]
%end.idx = add i64 %smax, 1
%cmp.n = icmp eq i64 %end.idx, %resume.val
br i1 %cmp.n, label %L2, label %if
if: ; preds = %middle.block, %if
%"#s1.03" = phi i64 [ %24, %if ], [ %resume.val, %middle.block ]
%20 = add i64 %"#s1.03", -1, !dbg !3370
%21 = getelementptr double* %7, i64 %20, !dbg !3370
%22 = load double* %21, align 8, !dbg !3370
%23 = fmul double %22, 2.000000e+00, !dbg !3370
store double %23, double* %21, align 8, !dbg !3370
%24 = add nsw i64 %"#s1.03", 1, !dbg !3371
%25 = icmp slt i64 %"#s1.03", %4, !dbg !3369
br i1 %25, label %if, label %L2, !dbg !3369, !llvm.vectorizer.already_vectorized !3372
L2: ; preds = %if, %middle.block, %top
ret void, !dbg !3371
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment