This at least does something as you say on Julia 1.5.1 (with this modification), not on 1.6, and I’m not sure where to apply it (or fix for 1.6):
julia> @inline function expect(b::Bool)
Core.Intrinsics.llvmcall(("declare i1 @llvm.expect.i1(i1, i1)", """
%b = trunc i8 %0 to i1
%actual = call i1 @llvm.expect.i1(i1 %b, i1 true)
%byte = zext i1 %actual to i8
ret i8 %byte
"""), Bool, Tuple{Bool}, b)
end
expect (generic function with 1 method)
julia> expect(true)
ERROR: Module IR does not contain specified entry function
Stacktrace:
[1] expect(b::Bool)
@ Main ./REPL[112]:2
[2] top-level scope
@ REPL[113]:1
Anyway, ifelse, seemed to work, while the division wasn’t the exact first instruction 8maybe a good choice). It’s good to know, while it didn’t really help me optimize in this case.