Is the julia compiler smart enough to treat `x in (y,)` the same as `x == y`?

I’m just wondering if the julia compiler can treat a expression like x in (y,) the same as x == y, assuming that the right argument for in is always a 1-sized tuple. Moreover, what would be the performance difference between these two pieces of code?

Edit: typo in the title

1 Like

Sure looks like it!

julia> @code_native debuginfo=:none 1 in (1,)

        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register %rbp
        cmpq    %rcx, (%rdx)
        sete    %al
        popq    %rbp
        retq
julia> @code_native debuginfo=:none 1 == 1

        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register %rbp
        cmpq    %rdx, %rcx
        sete    %al
        popq    %rbp
        retq
10 Likes

Oh that’s cool! i guess there’s no performance difference then

2 Likes