Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid promote for homogeneous tuples #3

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

nsajko
Copy link
Collaborator

@nsajko nsajko commented Jan 15, 2025

According to Cthulhu's descend, promote doesn't get optimized out otherwise:

using CheckedSizeProduct
function f(t::Tuple{Int, Vararg{Int}})
    p = checked_size_product(t)
    if p isa Int
        p
    else
        throw(nothing)
    end
end
using Cthulhu: descend
descend(f, Tuple{Tuple{Vararg{Int, 15}}})

According to Cthulhu's `descend`, `promote` doesn't get optimized out
otherwise:

```julia
using CheckedSizeProduct
function f(t::Tuple{Int, Vararg{Int}})
    p = checked_size_product(t)
    if p isa Int
        p
    else
        throw(nothing)
    end
end
using Cthulhu: descend
descend(f, Tuple{Tuple{Vararg{Int, 15}}})
```
@nsajko
Copy link
Collaborator Author

nsajko commented Jan 15, 2025

Before this PR, on the main branch, the above script shows the following:

[...]
;  @ REPL[2]:2 within `f`
; ┌ @ /home/nsajko/src/gitlab.com/nsajko/CheckedSizeProduct/src/CheckedSizeProduct.jl:70 within `checked_size_product`
   %5 = getelementptr inbounds [15 x i64], ptr %0, i64 0, i64 4
   %6 = getelementptr inbounds [15 x i64], ptr %0, i64 0, i64 8
   %7 = getelementptr inbounds [15 x i64], ptr %0, i64 0, i64 12
   %8 = getelementptr inbounds [15 x i64], ptr %0, i64 0, i64 14
; │┌ @ promotion.jl:416 within `promote`
    %9 = load <4 x i64>, ptr %0, align 8
    store <4 x i64> %9, ptr %1, align 8
    %10 = getelementptr inbounds [15 x i64], ptr %1, i64 0, i64 4
    %11 = load <4 x i64>, ptr %5, align 8
    store <4 x i64> %11, ptr %10, align 8
    %12 = getelementptr inbounds [15 x i64], ptr %1, i64 0, i64 8
    %13 = load <4 x i64>, ptr %6, align 8
    store <4 x i64> %13, ptr %12, align 8
    %14 = getelementptr inbounds [15 x i64], ptr %1, i64 0, i64 12
    %15 = load <2 x i64>, ptr %7, align 8
    store <2 x i64> %15, ptr %14, align 8
    %16 = getelementptr inbounds [15 x i64], ptr %1, i64 0, i64 14
    %17 = load i64, ptr %8, align 8
    store i64 %17, ptr %16, align 8
; │└
; │ @ /home/nsajko/src/gitlab.com/nsajko/CheckedSizeProduct/src/CheckedSizeProduct.jl:71 within `checked_size_product`
[...]

@nsajko nsajko merged commit b336ae0 into JuliaArrays:main Jan 15, 2025
4 checks passed
@nsajko nsajko deleted the avoid_promotion branch January 15, 2025 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant