Skip to content

Instantly share code, notes, and snippets.

@NHDaly
Created March 14, 2022 13:45
Show Gist options
  • Save NHDaly/84b685d302dd77e67dbbe56cf3f2fe06 to your computer and use it in GitHub Desktop.
Save NHDaly/84b685d302dd77e67dbbe56cf3f2fe06 to your computer and use it in GitHub Desktop.
`@code_llvm make_str("hi")`
julia> @code_llvm make_str("hi")
; @ REPL[20]:1 within `make_str`
define [1 x {}*] @julia_make_str_596({}* nonnull %0) #0 {
top:
; @ REPL[20]:2 within `make_str`
; ┌ @ Base.jl:178 within `sizeof`
%1 = bitcast {}* %0 to i64*
%2 = load i64, i64* %1, align 8
; └
; ┌ @ int.jl:83 within `<`
%3 = icmp ugt i64 %2, 7
; └
br i1 %3, label %common.ret, label %L5
L5: ; preds = %top
; @ REPL[20]:4 within `make_str`
; ┌ @ iterators.jl:166 within `iterate` @ iterators.jl:167 @ strings/basic.jl:755 @ strings/basic.jl:755
; │┌ @ int.jl:487 within `<` @ int.jl:480
%.not = icmp eq i64 %2, 0
; │└
br i1 %.not, label %L137, label %L48
L48: ; preds = %L5
; │┌ @ strings/basic.jl:753 within `getindex`
; ││┌ @ strings/string.jl:105 within `codeunit`
; │││┌ @ strings/string.jl:98 within `pointer` @ strings/string.jl:97
; ││││┌ @ pointer.jl:59 within `unsafe_convert`
%4 = bitcast {}* %0 to {}**
%5 = getelementptr inbounds {}*, {}** %4, i64 1
; ││││└
; ││││ @ strings/string.jl:98 within `pointer`
; ││││┌ @ pointer.jl:159 within `+`
%6 = bitcast {}** %5 to i8*
; │││└└
; │││┌ @ pointer.jl:105 within `unsafe_load` @ pointer.jl:105
%7 = load i8, i8* %6, align 1
; └└└└
; @ REPL[20]:5 within `make_str`
; ┌ @ boot.jl:762 within `UInt64`
; │┌ @ boot.jl:734 within `toUInt64`
%8 = zext i8 %7 to i64
; └└
; ┌ @ int.jl:503 within `<<` @ int.jl:496
%9 = shl nuw nsw i64 %8, 8
; └
; @ REPL[20]:6 within `make_str`
; ┌ @ iterators.jl:167 within `iterate` @ strings/basic.jl:755
; │┌ @ int.jl:487 within `<` @ int.jl:480
%.not3541.not = icmp eq i64 %2, 1
; │└
br i1 %.not3541.not, label %L137, label %L118.lr.ph
L118.lr.ph: ; preds = %L48
%10 = add nsw i64 %2, -1
%min.iters.check = icmp ult i64 %10, 4
br i1 %min.iters.check, label %L118, label %vector.ph
vector.ph: ; preds = %L118.lr.ph
%n.vec = and i64 %10, -4
%ind.end = or i64 %n.vec, 1
%ind.end47 = or i64 %n.vec, 2
%11 = insertelement <4 x i64> <i64 poison, i64 0, i64 0, i64 0>, i64 %9, i32 0
br label %vector.body
vector.body: ; preds = %vector.body, %vector.ph
%index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
%vec.phi = phi <4 x i64> [ %11, %vector.ph ], [ %25, %vector.body ]
%vec.ind = phi <4 x i64> [ <i64 2, i64 3, i64 4, i64 5>, %vector.ph ], [ %vec.ind.next, %vector.body ]
%offset.idx = or i64 %index, 1
; │┌ @ strings/basic.jl:753 within `getindex`
; ││┌ @ strings/string.jl:105 within `codeunit`
; │││┌ @ strings/string.jl:98 within `pointer`
; ││││┌ @ pointer.jl:160 within `-`
%12 = getelementptr i8, i8* %6, i64 %offset.idx
; │││└└
; │││┌ @ pointer.jl:105 within `unsafe_load` @ pointer.jl:105
%13 = bitcast i8* %12 to <4 x i8>*
%wide.load = load <4 x i8>, <4 x i8>* %13, align 1
; └└└└
; @ REPL[20]:5 within `make_str`
; ┌ @ boot.jl:762 within `UInt64`
; │┌ @ boot.jl:734 within `toUInt64`
%14 = zext <4 x i8> %wide.load to <4 x i64>
; └└
; ┌ @ operators.jl:591 within `*` @ int.jl:88
%15 = shl <4 x i64> %vec.ind, <i64 3, i64 3, i64 3, i64 3>
; └
; ┌ @ int.jl:503 within `<<`
; │┌ @ int.jl:481 within `<=`
%16 = icmp slt <4 x i64> %15, zeroinitializer
; │└
; │ @ int.jl:503 within `<<` @ int.jl:496
%17 = shl <4 x i64> %14, %15
%18 = icmp ugt <4 x i64> %15, <i64 63, i64 63, i64 63, i64 63>
%19 = select <4 x i1> %18, <4 x i64> zeroinitializer, <4 x i64> %17
; │ @ int.jl:503 within `<<`
; │┌ @ int.jl:85 within `-`
%20 = sub <4 x i64> zeroinitializer, %15
; │└
; │┌ @ int.jl:495 within `>>`
%21 = lshr <4 x i64> %14, %20
%22 = icmp ugt <4 x i64> %20, <i64 63, i64 63, i64 63, i64 63>
%23 = select <4 x i1> %22, <4 x i64> zeroinitializer, <4 x i64> %21
; │└
; │┌ @ essentials.jl:490 within `ifelse`
%24 = select <4 x i1> %16, <4 x i64> %23, <4 x i64> %19
; └└
; ┌ @ int.jl:365 within `|`
%25 = or <4 x i64> %24, %vec.phi
%index.next = add nuw i64 %index, 4
%vec.ind.next = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
%26 = icmp eq i64 %index.next, %n.vec
br i1 %26, label %middle.block, label %vector.body
middle.block: ; preds = %vector.body
; └
; @ REPL[20]:6 within `make_str`
; ┌ @ iterators.jl:167 within `iterate` @ strings/basic.jl:755
%27 = call i64 @llvm.vector.reduce.or.v4i64(<4 x i64> %25)
%cmp.n = icmp eq i64 %10, %n.vec
br i1 %cmp.n, label %L137, label %L118
L118: ; preds = %L118, %middle.block, %L118.lr.ph
%28 = phi i64 [ %value_phi1343, %L118 ], [ %ind.end, %middle.block ], [ 1, %L118.lr.ph ]
%29 = phi i64 [ %44, %L118 ], [ %27, %middle.block ], [ %9, %L118.lr.ph ]
%value_phi1343 = phi i64 [ %32, %L118 ], [ %ind.end47, %middle.block ], [ 2, %L118.lr.ph ]
; │┌ @ strings/basic.jl:753 within `getindex`
; ││┌ @ strings/string.jl:105 within `codeunit`
; │││┌ @ strings/string.jl:98 within `pointer`
; ││││┌ @ pointer.jl:160 within `-`
%30 = getelementptr i8, i8* %6, i64 %28
; │││└└
; │││┌ @ pointer.jl:105 within `unsafe_load` @ pointer.jl:105
%31 = load i8, i8* %30, align 1
; │└└└
; │┌ @ int.jl:87 within `+`
%32 = add nuw nsw i64 %value_phi1343, 1
; └└
; @ REPL[20]:5 within `make_str`
; ┌ @ boot.jl:762 within `UInt64`
; │┌ @ boot.jl:734 within `toUInt64`
%33 = zext i8 %31 to i64
; └└
; ┌ @ operators.jl:591 within `*` @ int.jl:88
%34 = shl i64 %value_phi1343, 3
; └
; ┌ @ int.jl:503 within `<<`
; │┌ @ int.jl:481 within `<=`
%35 = icmp slt i64 %34, 0
; │└
; │ @ int.jl:503 within `<<` @ int.jl:496
%36 = shl i64 %33, %34
%37 = icmp ugt i64 %34, 63
%38 = select i1 %37, i64 0, i64 %36
; │ @ int.jl:503 within `<<`
; │┌ @ int.jl:85 within `-`
%39 = sub i64 0, %34
; │└
; │┌ @ int.jl:495 within `>>`
%40 = lshr i64 %33, %39
%41 = icmp ugt i64 %39, 63
%42 = select i1 %41, i64 0, i64 %40
; │└
; │┌ @ essentials.jl:490 within `ifelse`
%43 = select i1 %35, i64 %42, i64 %38
; └└
; ┌ @ int.jl:365 within `|`
%44 = or i64 %43, %29
; └
; @ REPL[20]:6 within `make_str`
; ┌ @ iterators.jl:167 within `iterate` @ strings/basic.jl:755
; │┌ @ int.jl:487 within `<` @ int.jl:480
%exitcond.not = icmp eq i64 %value_phi1343, %2
; │└
br i1 %exitcond.not, label %L137, label %L118
common.ret: ; preds = %L137, %top
%.pn36 = phi {}* [ %45, %L137 ], [ %0, %top ]
; └
; @ REPL[20] within `make_str`
%common.ret.op = insertvalue [1 x {}*] zeroinitializer, {}* %.pn36, 0
ret [1 x {}*] %common.ret.op
L137: ; preds = %L118, %middle.block, %L48, %L5
%value_phi25 = phi i64 [ 0, %L5 ], [ %9, %L48 ], [ %27, %middle.block ], [ %44, %L118 ]
; @ REPL[20]:7 within `make_str`
; ┌ @ REPL[8]:2 within `UnionUIntOrString`
%45 = call nonnull {}* @ijl_box_uint64(i64 zeroext %value_phi25)
br label %common.ret
; └
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment