-
-
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
unnecessary slow code generated by if-then statement #7836
Comments
See other issues where this has been brought up: |
I'm surprised this isn't caught by llvm's constant folding though. |
Thanks @StephenVavasis! Because of branch-point prediction, it's basically irrelevant whether constant folding works or not---the CPU will learn that only one branch is ever taken. The far more serious issue is a type inference problem. Check the memory allocation under julia> code_typed(t2, (Float64,))
1-element Array{Any,1}:
:($(Expr(:lambda, {:x}, {{:s,symbol("#s121"),symbol("#s120"),symbol("#s119"),:i,:_var0,:_var1,:_var2},{{:x,Any,0},{:s,Any,2},{symbol("#s121"),UnitRange{Int64},18},{symbol("#s120"),Int64,2},{symbol("#s119"),(Int64,Int64),18},{:i,Int64,18},{:_var0,Float64,18},{:_var1,Int64,18},{:_var2,Int64,18}},{}}, :(begin # none, line 2: What are those |
According to Tim Holy, the problem is not just with dead code elimination. -- Steve Vavasis On Mon, 4 Aug 2014, Jacob Quinn wrote:
|
Yes it looks like the unreachable code is poisoning something. Should be possible to fix this. |
You probably already discovered this yourself, but if you change it to
then the type inference is perfect. So it's the fact that it knows at compile time that it's unreachable that triggers the poisoning. |
I would like to add: you might wonder why I would put "if true" in a Julia -- Steve Vavasis On Mon, 4 Aug 2014, Tim Holy wrote:
|
Steve, as an aside, the Logging.jl package has a |
@StephenVavasis – that's a totally reasonable thing to do and obviously should work :-) |
I have a fix for this. |
Yay, very nice! |
The function
t2()
below runs much more slowly thant1()
apparently because a lot of extra unnecessary code is being generated by the compiler.The text was updated successfully, but these errors were encountered: