-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fields of global constant immutables cannot be constant-folded #18387
Comments
This is a regression from v0.4: julia> f() = 2im
f (generic function with 1 method)
julia> @code_llvm f()
define void @julia_f_21209(%Complex.12* sret) {
top:
store %Complex.12 { i64 0, i64 2 }, %Complex.12* %0, align 8
ret void
} |
See also julia> g(x) = 2//3 * x
g (generic function with 1 method)
julia> @code_llvm g(2f0)
; Function Attrs: uwtable
define float @julia_g_71906(float) #0 {
top:
%1 = alloca %Rational, align 8
call void @julia_Type_71907(%Rational* noalias nonnull sret %1, %jl_value_t* inttoptr (i64 2244157328 to %jl_value_t*), i64 2, i64 3) #1
%2 = getelementptr inbounds %Rational, %Rational* %1, i64 0, i32 0
%3 = load i64, i64* %2, align 8
%4 = sitofp i64 %3 to float
%5 = getelementptr inbounds %Rational, %Rational* %1, i64 0, i32 1
%6 = load i64, i64* %5, align 8
%7 = sitofp i64 %6 to float
%8 = fdiv float %4, %7
%9 = fmul float %8, %0
ret float %9
} |
This is a different problem.... |
@yuyichao It's definitely part of this problem. |
Well #18387 (comment) is a inlining problem. |
@yuyichao I think I have a fix for that particular inlining problem that should help with (but not resolve entirely) the problem here. Will make a WIP PR shortly. |
Sure, I'll be happily surprised if it helps with #18387 (comment) though since it doesn't have any constant immutable, is not a regression and is simply because the Rational constructor is too complicated to be inlined (it simplifies the ratio first). |
Finally found it, the rational issue is a dup of #11522 |
This was probably fixed by #21277. |
any way to add a regression test for it? |
A benchmark might make more sense than a regression test, since this is only a matter of performance, not correctness. But this would work: 0.5 julia> test18387() = im.re ? 0 : 0.0
test18387 (generic function with 1 method)
julia> @inferred(test18387())
ERROR: return type Float64 does not match inferred return type Union{Float64,Int64}
in error(::String) at ./error.jl:21 latest beta julia> test18387() = im.re ? 0 : 0.0
test18387 (generic function with 1 method)
julia> @inferred(test18387())
0.0 |
Min-repro:
Symptom:
This makes
z * im
substantially slower thanz * Complex(false, true)
.If this cannot be easily fixed, it might be worth introducing
@im
forim
. Note the performance difference:The text was updated successfully, but these errors were encountered: