Last active
July 18, 2018 09:37
-
-
Save SimonDanisch/812e01d7183681ed414932c8f7b533d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unroll(f, ::Val{1}) = f() | |
function unroll(f, ::Val{N}) where N | |
f(); unroll(f, Val(N-1)) | |
end | |
function test() | |
box = Ref(1.0) # explicitely box to make escape analysis easier | |
unroll(()-> box[] += sin(box[]), Val(3)) | |
box[] | |
end | |
# as you can see, the box will get eliminated on julia 0.7! | |
julia> @code_llvm test() | |
define double @julia_test_33284() #0 { | |
top: | |
%0 = call double @julia_sin_33229(double 1.000000e+00) | |
%1 = fadd double %0, 1.000000e+00 | |
%2 = call double @julia_sin_33229(double %1) | |
%3 = fadd double %1, %2 | |
%4 = call double @julia_sin_33229(double %3) | |
%5 = fadd double %3, %4 | |
ret double %5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment