How to avoid compilation of an uncalled function

You can use the @nospecialize macro at the beginning of the generated function, as follows:

macro valuedispatch_macro(lower::Int, upper::Int, val, fun)
    ex = valuedispatch_expr(Val(lower), Val(upper), esc(val), esc(fun))
    return quote
        @nospecialize
        $ex
        return nothing
    end
end

Because valuedispatch_1_32 is now a generic function, it knows nothing about the function myfun being passed in, and so cannot precompile it.