Inference failure on tuple

Yes, but it looks to me like dead code elimination currently comes after type inference is already done. This is totally reasonable of course, but there are cases, like the one in the OP, where (re-)running type inference after dead code elimination (at the Julia AST level, I suppose) could be beneficial, in the sense of potentially producing more performant code without the user or Julia Base developer having to jump through additional hoops (user having to use Val, addition of the Val methods for ntuple in base, in the OP case).

Here’s a simpler example:

function baz1()
    n = 2
    if n > 1
        1
    else
        1.
    end
end

baz2() = 1

Even though baz1 and baz2 always return the same underlying value, 1, baz1 returns it boxed, and the code_typed, code_llvm, and code_native are all different for baz1 and baz2. This is despite the fact that dead code elimination happens (I believe) for baz1 between the code_typed and the code_llvm stage.