Can you post an example of the code?
I saw this example from this old thread which I have been able to recreate:
const CODES = (2, 3, 5, 7, 11)
const RCODES = reverse(CODES)
f(x) = 0
f(x, y, ys...) = x == y ? 1 + length(ys) : f(x, ys...)
findcode3(x) = f(x, RCODES...)
@code_llvm findcode3(3)
Additionally, I can edit the code to get close to what I wanted originally as we can see that there’s a table lookup happening in the LLVM:
const RETURNVALUES = (0, 1, 5, 10, 11, 13)
const RRETURNVALUES = reverse(RETURNVALUES)
h(x) = RETURNVALUES[0]
h(x, y, ys...) = x == y ? RRETURNVALUES[length(ys)+1] : h(x, ys...)
hindcode3(x) = h(x, RCODES...)
hindcode3(3)
@code_llvm hindcode3(3)
; Function Attrs: uwtable
define i64 @julia_hindcode3_1356(i64 signext %0) #0 {
top:
; ┌ @ c:\Users\jmmsm\Documents\GitHub\speedy_julia\examples\ss_try2.jl:23 within `h`
%switch.tableidx = add i64 %0, -2
%1 = icmp ult i64 %switch.tableidx, 10
br i1 %1, label %switch.hole_check, label %L16
L16: ; preds = %switch.hole_check, %top
; │ @ c:\Users\jmmsm\Documents\GitHub\speedy_julia\examples\ss_try2.jl:23 within `h` @ c:\Users\jmmsm\Documents\GitHub\speedy_julia\examples\ss_try2.jl:23 @ c:\Users\jmmsm\Documents\GitHub\speedy_julia\examples\ss_try2.jl:23 @ c:\Users\jmmsm\Documents\GitHub\speedy_julia\examples\ss_try2.jl:23 @ c:\Users\jmmsm\Documents\GitHub\speedy_julia\examples\ss_try2.jl:23
%2 = call nonnull {}* @j_h_1358(i64 signext %0) #0
call void @llvm.trap()
unreachable
switch.hole_check: ; preds = %top
; │ @ c:\Users\jmmsm\Documents\GitHub\speedy_julia\examples\ss_try2.jl:23 within `h`
%switch.maskindex = trunc i64 %switch.tableidx to i16
%switch.shifted = lshr i16 555, %switch.maskindex
%3 = and i16 %switch.shifted, 1
%switch.lobit.not = icmp eq i16 %3, 0
br i1 %switch.lobit.not, label %L16, label %switch.lookup
switch.lookup: ; preds = %switch.hole_check
%switch.gep = getelementptr inbounds [10 x i64], [10 x i64]* @switch.table.julia_hindcode3_1356, i64 0, i64 %switch.tableidx
%switch.load = load i64, i64* %switch.gep, align 8
ret i64 %switch.load
; └
}